UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xf6 in position 79: invalid start byte

8 months ago

Hello! I am really sorry if that is not place to ask but ı have been having this error for 3 days and ı do not know why? You can read in details from django formm here as well;

https://forum.djangoproject.com/t/unicodedecodeerror-utf-8-codec-cant-decode-byte-0xf6-in-position-79-invalid-start-byte/33962/29

Basicaly, I have a django project which ı wanted to connect to railway postgres service but whenever ı want to add railway postgress to my settings.py ı have the error mentioned in the title. I will give some part of the traceback and too.

I tried going back to sqlite which django comes with everything works but when ı add railway postgres service it just breaks.

I tried removing and recreating virtual env.

I tried hard coding the dbpassword

ı wrote an small script to check if any of my .py files have a character that doesn't fit utf8

I contacted django community to ask this but for 3 days ı couldn't solve it. So ı am asking help by any means.

So please if there is anyth solution can help me ı would be more than happy!

Here is the some of the traceback

DATABASES = {
    'default': {
        #'ENGINE': 'django.db.backends.sqlite3',
        #'NAME': BASE_DIR / 'db.sqlite3',
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'railway',
        'USER': 'postgres',
        'PASSWORD': os.environ.get('DB_PASSWORD'),
        'HOST': 'postgres.railway.internal',
        'PORT': '5432',
    }
}
  File "C:\Users\cetin\OneDrive\Masaüstü\ecom\virt\Lib\site-packages\django\db\backends\base\base.py", line 279, in ensure_connection
    self.connect()
  File "C:\Users\cetin\OneDrive\Masaüstü\ecom\virt\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cetin\OneDrive\Masaüstü\ecom\virt\Lib\site-packages\django\db\backends\base\base.py", line 256, in connect
    self.connection = self.get_new_connection(conn_params)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cetin\OneDrive\Masaüstü\ecom\virt\Lib\site-packages\django\utils\asyncio.py", line 26, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cetin\OneDrive\Masaüstü\ecom\virt\Lib\site-packages\django\db\backends\postgresql\base.py", line 350, in get_new_connection
    connection = self.Database.connect(**conn_params)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cetin\OneDrive\Masaüstü\ecom\virt\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 0xf6 in position 79: invalid start byte

1 Replies

8 months ago

From your forum post -

django.db.utils.OperationalError: could not translate host name "postgres.railway.internal" to address: No such host is known.

This is a private domain, it can only be accessed by services running on Railway within the project that also contains the database.

If you run your django app anywhere else you need to use the public host and port of the database.


UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xf6 in position 79: invalid start byte - Railway Help Station