1

I'm working on a team project on DRF, which uses PostgreSQL-based DB, my local PostgreSQL version is 17. The problem is that all of my colleagues have Ubuntu OS on their devices (and the project itself was started on Ubuntu), while my laptop has Windows 10 (x64). So, when my colleagues run project (to lurk in swagger, for example) or test it on their devices, everything works well. While I, obtaining the project from its repo, cannot run it, cannot test it, as in all those cases it returns an error:

dsn = 'dbname=postgres client_encoding=UTF8 user=postgres password=postgres host=db port=5432', connection_factory = None
cursor_factory = <class 'psycopg2.extensions.cursor'>, kwargs = {'client_encoding': 'UTF8', 'dbname': 'postgres', 'host': 'db', 'password': 'postgres', ...}   
kwasync = {}

    def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs):
        """
        Create a new database connection.

        The connection parameters can be specified as a string:

            conn = psycopg2.connect("dbname=test user=postgres password=secret")

        or using a set of keyword arguments:

            conn = psycopg2.connect(database="test", user="postgres", password="secret")

        Or as a mix of both. The basic connection parameters are:

        - *dbname*: the database name
        - *database*: the database name (only as keyword argument)
        - *user*: user name used to authenticate
        - *password*: password used to authenticate
        - *host*: database host address (defaults to UNIX socket if not provided)
        - *port*: connection port number (defaults to 5432 if not provided)

        Using the *connection_factory* parameter a different class or connections
        factory can be specified. It should be a callable object taking a dsn
        argument.

        Using the *cursor_factory* parameter, a new default cursor factory will be
        used by cursor().

        Using *async*=True an asynchronous connection will be created. *async_* is
        a valid alias (for Python versions where ``async`` is a keyword).

        Any other keyword parameter will be passed to the underlying client
        library: the list of supported parameters depends on the library version.

        """
        kwasync = {}
        if 'async' in kwargs:
            kwasync['async'] = kwargs.pop('async')
        if 'async_' in kwargs:
            kwasync['async_'] = kwargs.pop('async_')

        dsn = _ext.make_dsn(dsn, **kwargs)
>       conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
E       UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 47: invalid continuation byte

..\.venv\Lib\site-packages\psycopg2\__init__.py:122: UnicodeDecodeError

I've tried to fix it by numerous ways: installed psycopg (3) instead of psycopg2 (via uv add, we have .toml file), added the path to Postgres's bin folder to system environment path, updated Postgres (it was 12 previously, I updated it to 17), deleted project completely and cloned it again after all changes, several times re-created .venv folder inside the project - all to no result. We checked .env file's content searching for non-utf8 symbols, but realized that those #47 or #61 symbols mentioned in the error description are usual Latin symbols, written manually.

I'm definitely going to install Ubuntu as a second OS on my laptop (hope this old guy won't die from the heart attack)... but imagine it wouldn't help as well. Then I would simply run out of possible ideas about the error. Even ChatGPT/DeepSeek weren't able to help me, as I thoroughly followed their instructions. That's why I want to make sure the problem can't be solved within Windows.

The entire traceback from a pytest attempt:

==================================================================== test session starts =====================================================================
platform win32 -- Python 3.12.3, pytest-8.3.5, pluggy-1.5.0
django: version: 5.2, settings: config.django.settings (from ini)
rootdir: C:\Users\HP\PycharmProjects\helpdesk-3-backend
configfile: pytest.ini
plugins: Faker-37.1.0, django-4.11.1, factoryboy-2.7.0
collected 4 items                                                                                                                                             

apps\tickets\tests\test_views.py::test_ticket_list_view ERROR                                                                                           [ 25%]
apps\tickets\tests\test_views.py::test_ticket_retrieve_view ERROR                                                                                       [ 50%]
apps\tickets\tests\test_views.py::test_ticket_update_view ERROR                                                                                         [ 75%]
apps\tickets\tests\test_views.py::test_update_completed_ticket ERROR                                                                                    [100%]

=========================================================================== ERRORS =========================================================================== 
__________________________________________________________ ERROR at setup of test_ticket_list_view ___________________________________________________________ 

request = <SubRequest '_django_db_marker' for <Function test_ticket_list_view>>

    @pytest.fixture(autouse=True)
    def _django_db_marker(request: pytest.FixtureRequest) -> None:
        """Implement the django_db marker, internal to pytest-django."""
        marker = request.node.get_closest_marker("django_db")
        if marker:
>           request.getfixturevalue("_django_db_helper")

..\.venv\Lib\site-packages\pytest_django\plugin.py:552:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  
..\.venv\Lib\site-packages\pytest_django\fixtures.py:198: in django_db_setup
    db_cfg = setup_databases(
..\.venv\Lib\site-packages\django\test\utils.py:204: in setup_databases
    connection.creation.create_test_db(
..\.venv\Lib\site-packages\django\db\backends\base\creation.py:62: in create_test_db
    self._create_test_db(verbosity, autoclobber, keepdb)
..\.venv\Lib\site-packages\django\db\backends\base\creation.py:202: in _create_test_db
    with self._nodb_cursor() as cursor:
..\..\..\AppData\Local\Programs\Python\Python312\Lib\contextlib.py:137: in __enter__
    return next(self.gen)
..\.venv\Lib\site-packages\django\db\backends\postgresql\base.py:507: in _nodb_cursor
    with super()._nodb_cursor() as cursor:
..\..\..\AppData\Local\Programs\Python\Python312\Lib\contextlib.py:137: in __enter__
    return next(self.gen)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:712: in _nodb_cursor
    with conn.cursor() as cursor:
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:320: in cursor
    return self._cursor()
..\.venv\Lib\site-packages\django\db\backends\base\base.py:296: in _cursor
    self.ensure_connection()
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:279: in ensure_connection
    self.connect()
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:256: in connect
    self.connection = self.get_new_connection(conn_params)
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\postgresql\base.py:332: in get_new_connection
    connection = self.Database.connect(**conn_params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  

dsn = 'dbname=postgres client_encoding=UTF8 user=postgres password=postgres host=db port=5432', connection_factory = None
cursor_factory = <class 'psycopg2.extensions.cursor'>, kwargs = {'client_encoding': 'UTF8', 'dbname': 'postgres', 'host': 'db', 'password': 'postgres', ...}   
kwasync = {}

    def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs):
        """
        Create a new database connection.

        The connection parameters can be specified as a string:

            conn = psycopg2.connect("dbname=test user=postgres password=secret")

        or using a set of keyword arguments:

            conn = psycopg2.connect(database="test", user="postgres", password="secret")

        Or as a mix of both. The basic connection parameters are:

        - *dbname*: the database name
        - *database*: the database name (only as keyword argument)
        - *user*: user name used to authenticate
        - *password*: password used to authenticate
        - *host*: database host address (defaults to UNIX socket if not provided)
        - *port*: connection port number (defaults to 5432 if not provided)

        Using the *connection_factory* parameter a different class or connections
        factory can be specified. It should be a callable object taking a dsn
        argument.

        Using the *cursor_factory* parameter, a new default cursor factory will be
        used by cursor().

        Using *async*=True an asynchronous connection will be created. *async_* is
        a valid alias (for Python versions where ``async`` is a keyword).

        Any other keyword parameter will be passed to the underlying client
        library: the list of supported parameters depends on the library version.

        """
        kwasync = {}
        if 'async' in kwargs:
            kwasync['async'] = kwargs.pop('async')
        if 'async_' in kwargs:
            kwasync['async_'] = kwargs.pop('async_')

        dsn = _ext.make_dsn(dsn, **kwargs)
>       conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
E       UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 47: invalid continuation byte

..\.venv\Lib\site-packages\psycopg2\__init__.py:122: UnicodeDecodeError
------------------------------------------------------------------- Captured stderr setup -------------------------------------------------------------------- 
Creating test database for alias 'default'...
________________________________________________________ ERROR at setup of test_ticket_retrieve_view _________________________________________________________ 

request = <SubRequest '_django_db_marker' for <Function test_ticket_retrieve_view>>

    @pytest.fixture(autouse=True)
    def _django_db_marker(request: pytest.FixtureRequest) -> None:
        """Implement the django_db marker, internal to pytest-django."""
        marker = request.node.get_closest_marker("django_db")
        if marker:
>           request.getfixturevalue("_django_db_helper")

..\.venv\Lib\site-packages\pytest_django\plugin.py:552:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  
..\.venv\Lib\site-packages\pytest_django\fixtures.py:198: in django_db_setup
    db_cfg = setup_databases(
..\.venv\Lib\site-packages\django\test\utils.py:204: in setup_databases
    connection.creation.create_test_db(
..\.venv\Lib\site-packages\django\db\backends\base\creation.py:62: in create_test_db
    self._create_test_db(verbosity, autoclobber, keepdb)
..\.venv\Lib\site-packages\django\db\backends\base\creation.py:202: in _create_test_db
    with self._nodb_cursor() as cursor:
..\..\..\AppData\Local\Programs\Python\Python312\Lib\contextlib.py:137: in __enter__
    return next(self.gen)
..\.venv\Lib\site-packages\django\db\backends\postgresql\base.py:507: in _nodb_cursor
    with super()._nodb_cursor() as cursor:
..\..\..\AppData\Local\Programs\Python\Python312\Lib\contextlib.py:137: in __enter__
    return next(self.gen)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:712: in _nodb_cursor
    with conn.cursor() as cursor:
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:320: in cursor
    return self._cursor()
..\.venv\Lib\site-packages\django\db\backends\base\base.py:296: in _cursor
    self.ensure_connection()
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:279: in ensure_connection
    self.connect()
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:256: in connect
    self.connection = self.get_new_connection(conn_params)
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\postgresql\base.py:332: in get_new_connection
    connection = self.Database.connect(**conn_params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  

dsn = 'dbname=postgres client_encoding=UTF8 user=postgres password=postgres host=db port=5432', connection_factory = None
cursor_factory = <class 'psycopg2.extensions.cursor'>, kwargs = {'client_encoding': 'UTF8', 'dbname': 'postgres', 'host': 'db', 'password': 'postgres', ...}   
kwasync = {}

    def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs):
        """
        Create a new database connection.

        The connection parameters can be specified as a string:

            conn = psycopg2.connect("dbname=test user=postgres password=secret")

        or using a set of keyword arguments:

            conn = psycopg2.connect(database="test", user="postgres", password="secret")

        Or as a mix of both. The basic connection parameters are:

        - *dbname*: the database name
        - *database*: the database name (only as keyword argument)
        - *user*: user name used to authenticate
        - *password*: password used to authenticate
        - *host*: database host address (defaults to UNIX socket if not provided)
        - *port*: connection port number (defaults to 5432 if not provided)

        Using the *connection_factory* parameter a different class or connections
        factory can be specified. It should be a callable object taking a dsn
        argument.

        Using the *cursor_factory* parameter, a new default cursor factory will be
        used by cursor().

        Using *async*=True an asynchronous connection will be created. *async_* is
        a valid alias (for Python versions where ``async`` is a keyword).

        Any other keyword parameter will be passed to the underlying client
        library: the list of supported parameters depends on the library version.

        """
        kwasync = {}
        if 'async' in kwargs:
            kwasync['async'] = kwargs.pop('async')
        if 'async_' in kwargs:
            kwasync['async_'] = kwargs.pop('async_')

        dsn = _ext.make_dsn(dsn, **kwargs)
>       conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
E       UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 47: invalid continuation byte

..\.venv\Lib\site-packages\psycopg2\__init__.py:122: UnicodeDecodeError
_________________________________________________________ ERROR at setup of test_ticket_update_view __________________________________________________________ 

request = <SubRequest '_django_db_marker' for <Function test_ticket_update_view>>

    @pytest.fixture(autouse=True)
    def _django_db_marker(request: pytest.FixtureRequest) -> None:
        """Implement the django_db marker, internal to pytest-django."""
        marker = request.node.get_closest_marker("django_db")
        if marker:
>           request.getfixturevalue("_django_db_helper")

..\.venv\Lib\site-packages\pytest_django\plugin.py:552:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  
..\.venv\Lib\site-packages\pytest_django\fixtures.py:198: in django_db_setup
    db_cfg = setup_databases(
..\.venv\Lib\site-packages\django\test\utils.py:204: in setup_databases
    connection.creation.create_test_db(
..\.venv\Lib\site-packages\django\db\backends\base\creation.py:62: in create_test_db
    self._create_test_db(verbosity, autoclobber, keepdb)
..\.venv\Lib\site-packages\django\db\backends\base\creation.py:202: in _create_test_db
    with self._nodb_cursor() as cursor:
..\..\..\AppData\Local\Programs\Python\Python312\Lib\contextlib.py:137: in __enter__
    return next(self.gen)
..\.venv\Lib\site-packages\django\db\backends\postgresql\base.py:507: in _nodb_cursor
    with super()._nodb_cursor() as cursor:
..\..\..\AppData\Local\Programs\Python\Python312\Lib\contextlib.py:137: in __enter__
    return next(self.gen)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:712: in _nodb_cursor
    with conn.cursor() as cursor:
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:320: in cursor
    return self._cursor()
..\.venv\Lib\site-packages\django\db\backends\base\base.py:296: in _cursor
    self.ensure_connection()
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:279: in ensure_connection
    self.connect()
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:256: in connect
    self.connection = self.get_new_connection(conn_params)
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\postgresql\base.py:332: in get_new_connection
    connection = self.Database.connect(**conn_params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

dsn = 'dbname=postgres client_encoding=UTF8 user=postgres password=postgres host=db port=5432', connection_factory = None
cursor_factory = <class 'psycopg2.extensions.cursor'>, kwargs = {'client_encoding': 'UTF8', 'dbname': 'postgres', 'host': 'db', 'password': 'postgres', ...}   
kwasync = {}

    def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs):
        """
        Create a new database connection.

        The connection parameters can be specified as a string:

            conn = psycopg2.connect("dbname=test user=postgres password=secret")

        or using a set of keyword arguments:

            conn = psycopg2.connect(database="test", user="postgres", password="secret")

        Or as a mix of both. The basic connection parameters are:

        - *dbname*: the database name
        - *database*: the database name (only as keyword argument)
        - *user*: user name used to authenticate
        - *password*: password used to authenticate
        - *host*: database host address (defaults to UNIX socket if not provided)
        - *port*: connection port number (defaults to 5432 if not provided)

        Using the *connection_factory* parameter a different class or connections
        factory can be specified. It should be a callable object taking a dsn
        argument.

        Using the *cursor_factory* parameter, a new default cursor factory will be
        used by cursor().

        Using *async*=True an asynchronous connection will be created. *async_* is
        a valid alias (for Python versions where ``async`` is a keyword).

        Any other keyword parameter will be passed to the underlying client
        library: the list of supported parameters depends on the library version.

        """
        kwasync = {}
        if 'async' in kwargs:
            kwasync['async'] = kwargs.pop('async')
        if 'async_' in kwargs:
            kwasync['async_'] = kwargs.pop('async_')

        dsn = _ext.make_dsn(dsn, **kwargs)
>       conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
E       UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 47: invalid continuation byte

..\.venv\Lib\site-packages\psycopg2\__init__.py:122: UnicodeDecodeError
_______________________________________________________ ERROR at setup of test_update_completed_ticket _______________________________________________________ 

request = <SubRequest '_django_db_marker' for <Function test_update_completed_ticket>>

    @pytest.fixture(autouse=True)
    def _django_db_marker(request: pytest.FixtureRequest) -> None:
        """Implement the django_db marker, internal to pytest-django."""
        marker = request.node.get_closest_marker("django_db")
        if marker:
>           request.getfixturevalue("_django_db_helper")

..\.venv\Lib\site-packages\pytest_django\plugin.py:552:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  
..\.venv\Lib\site-packages\pytest_django\fixtures.py:198: in django_db_setup
    db_cfg = setup_databases(
..\.venv\Lib\site-packages\django\test\utils.py:204: in setup_databases
    connection.creation.create_test_db(
..\.venv\Lib\site-packages\django\db\backends\base\creation.py:62: in create_test_db
    self._create_test_db(verbosity, autoclobber, keepdb)
..\.venv\Lib\site-packages\django\db\backends\base\creation.py:202: in _create_test_db
    with self._nodb_cursor() as cursor:
..\..\..\AppData\Local\Programs\Python\Python312\Lib\contextlib.py:137: in __enter__
    return next(self.gen)
..\.venv\Lib\site-packages\django\db\backends\postgresql\base.py:507: in _nodb_cursor
    with super()._nodb_cursor() as cursor:
..\..\..\AppData\Local\Programs\Python\Python312\Lib\contextlib.py:137: in __enter__
    return next(self.gen)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:712: in _nodb_cursor
    with conn.cursor() as cursor:
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:320: in cursor
    return self._cursor()
..\.venv\Lib\site-packages\django\db\backends\base\base.py:296: in _cursor
    self.ensure_connection()
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:279: in ensure_connection
    self.connect()
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\base\base.py:256: in connect
    self.connection = self.get_new_connection(conn_params)
..\.venv\Lib\site-packages\django\utils\asyncio.py:26: in inner
    return func(*args, **kwargs)
..\.venv\Lib\site-packages\django\db\backends\postgresql\base.py:332: in get_new_connection
    connection = self.Database.connect(**conn_params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  

dsn = 'dbname=postgres client_encoding=UTF8 user=postgres password=postgres host=db port=5432', connection_factory = None
cursor_factory = <class 'psycopg2.extensions.cursor'>, kwargs = {'client_encoding': 'UTF8', 'dbname': 'postgres', 'host': 'db', 'password': 'postgres', ...}
kwasync = {}

    def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs):
        """
        Create a new database connection.

        The connection parameters can be specified as a string:

            conn = psycopg2.connect("dbname=test user=postgres password=secret")

        or using a set of keyword arguments:

            conn = psycopg2.connect(database="test", user="postgres", password="secret")

        Or as a mix of both. The basic connection parameters are:

        - *dbname*: the database name
        - *database*: the database name (only as keyword argument)
        - *user*: user name used to authenticate
        - *password*: password used to authenticate
        - *host*: database host address (defaults to UNIX socket if not provided)
        - *port*: connection port number (defaults to 5432 if not provided)

        Using the *connection_factory* parameter a different class or connections
        factory can be specified. It should be a callable object taking a dsn
        argument.

        Using the *cursor_factory* parameter, a new default cursor factory will be
        used by cursor().

        Using *async*=True an asynchronous connection will be created. *async_* is
        a valid alias (for Python versions where ``async`` is a keyword).

        Any other keyword parameter will be passed to the underlying client
        library: the list of supported parameters depends on the library version.

        """
        kwasync = {}
        if 'async' in kwargs:
            kwasync['async'] = kwargs.pop('async')
        if 'async_' in kwargs:
            kwasync['async_'] = kwargs.pop('async_')

        dsn = _ext.make_dsn(dsn, **kwargs)
>       conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
E       UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 47: invalid continuation byte

..\.venv\Lib\site-packages\psycopg2\__init__.py:122: UnicodeDecodeError
================================================================== short test summary info =================================================================== 
ERROR apps\tickets\tests\test_views.py::test_ticket_list_view - UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 47: invalid continuation byte
ERROR apps\tickets\tests\test_views.py::test_ticket_retrieve_view - UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 47: invalid continuation byte
ERROR apps\tickets\tests\test_views.py::test_ticket_update_view - UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 47: invalid continuation byte
ERROR apps\tickets\tests\test_views.py::test_update_completed_ticket - UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 47: invalid continuation byte

An example of tests:

@pytest.mark.django_db
def test_ticket_retrieve_view(client_with_credentials: APIClient, ticket_case) -> None:
    url = reverse('tickets:ticket-detail', args=[ticket_case.id])
    response = client_with_credentials.get(url)

    assert response.status_code == 200

Update for @furas

Here is a little program (inside tickets app) to look through the dsn string by indexes returned in the error description. It doesn't work with psycopg somehow.

# -*- coding: utf-8 -*-

import psycopg2  # import psycopg returns an error (no pq wrapper)

dbname = "db_name"
user = "postgres"
password = "postgres"
host = "db"
port = "5432"

dsn = f"dbname={dbname} user={user} password={password} host={host} port={port}"
print(f"{dsn[47]}")
print(f"{dsn[61]}")
dsn = dsn.encode('cp1251').decode('utf-8')

# Подключаемся
conn = psycopg2.connect(dsn)
print(type(conn))
print(repr(conn))
print("Successfully connected!")
conn.close()

The result:

h
4
Traceback (most recent call last):
  File "...\src\apps\tickets\gg.py", line 17, in <module>
    conn = psycopg2.connect(dsn)
           ^^^^^^^^^^^^^^^^^^^^^
  File "...\.venv\Lib\site-packages\psycopg2\__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 47: invalid continuation byte

So, it returns corresponding symbols from dsn string, but at the attempt to operate with conn it returns that same error.

17
  • (1) There is a known issue in psycopg2 where it wil raise this error if you try to connect to the wrong prt, so check which port postgres is listening on (default is 5432) and that it matches your code. (2) What is the locale encoding on your PC (sorry I don't know how to find this on Windows) (3) Do you have the postgres command line client, psql(.exe) installed (this may help with debugging)? Commented Apr 22 at 8:30
  • @snakecharmerb, (1) Port in the .env file is 5432 (colleagues on Ubuntu use it). I have some PostgreSQL server in my pgAdmin (possibly, left from my previous attempts to make it work through Docker), where in properties/connection port is set on 5433. But I have already tried to align it in the server and in .env file, to no result (both to 5432 and 5433). In pgAdmin an attempt to connect to the DB server showed timeout error, and the error in the PyCharm console was the same as in the head of this ticket. Commented Apr 22 at 8:37
  • @snakecharmerb, (2) looked for it with PowerShell, it says: BodyName: koi8-r, EncodingName: Кириллица (Windows), HeaderName: windows-1251 and so on (Cyrillic). But I have tried to hardcode utf-8 encoding inside our project settings. To no result as well. Commented Apr 22 at 8:40
  • @snakecharmerb, (3) I have it inside pgAdmin, called PSQL Workspace, but it requires the connection to the DB server, which I cannot achieve so far. Commented Apr 22 at 8:42
  • 1
    I would first check which port postgres is listening on, verify that the port is accessible and only then then try to establish a connection either through pgadmin or (better) psql.exe to establish the required connection params. Commented Apr 22 at 12:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.