admin管理员组文章数量:1399947
I'm working on a personal project and using Docker and psycopg2 for the first time. I deployed a PostgreSQL server via Docker and am trying to connect to it using a Python script (with the goal of using Airflow DAGs in the future).
However, no matter what I try, I always get the same error when attempting to connect to the database:
Python Code is very simple :
import psycopg2
conn = psycopg2.connect(
dbname="testdb", user="user", password="pass", host="localhost", port=5432
)
conn.close()
Error Message :
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 103: invalid continuation byte
I have checked all parameters to ensure there are no non-UTF-8 characters, and PostgreSQL is correctly set to UTF-8.
What I have already tried without success:
- Checking Python's encoding -> UTF-8
- Adding client_encoding='utf8' to the connection
- Verifying that PostgreSQL encoding -> UTF8
- Checking Windows encoding settings
Despite all these attempts, the issue persists. Does anyone have an idea how to fix this? Thanks in advance for your help!
本文标签: pythonPsycopg2 to PostgresSQL DockerUTF8 Connection errorStack Overflow
版权声明:本文标题:python - Psycopg2 to PostgresSQL Docker - UTF8 Connection error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744125324a2591928.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论