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.
psql(.exe)installed (this may help with debugging)?BodyName: koi8-r, EncodingName: Кириллица (Windows), HeaderName: windows-1251and so on (Cyrillic). But I have tried to hardcodeutf-8encoding inside our project settings. To no result as well.