-
-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
psycopg2 The error message does not match the actual situation #1634
Comments
What is the encoding of your database? What happens if you connect with the same connection string using psycopg 3? |
UTF8, |
Sorry, apart from the encoding, I forgot to ask, what is the database language? What happens if you repeat the same operations using psycopg 3? Or with psql, using the same connection string? |
pip install psycopg |
I run into the same issue. If you run different versions of postgresql, then the database you want to connect to, might not be on the default postgresql port 5432, but on the next port 5433. If you use psycopg3 you will see the correct error message about a wrong port, but in psycopg2 an ambigious |
@eayin2 thank you for confirming that the issue is fixed in psycopg 3. Fixing the issue in psycopg2 is not trivial, so it will not be done, unless someone wants to fund for the development. |
我是来自中国程序员 , 我尝试解决了这个问题, 只需要使用psycopg3作为后端数据库的驱动就可以解决这个问题: 创建 SQLAlchemy 引擎和会话engine = create_engine(DATABASE_URL) Base = declarative_base() 解释: f"postgresql+psycopg://{config['username']}:{config['password']}@" 中的 psycopg 代表使用 psycopg3 |
solved for me after giving correct password for the user. |
This is a bug tracker
If you have a question, such has "how do you do X with Python/PostgreSQL/psycopg2" please write to the mailing list or open a question instead.
Please complete the following information:
Describe the bug
Please let us know:
Another computer is connected normally
I cannot connect to myself using PC20070343
conn = psycopg2.connect( host="pc20070343", port="5432")
Traceback (most recent call last):
File "C:\Users\Ot903056\PycharmProjects\PublicServer\test.py", line 4, in
conn = psycopg2.connect(
^^^^^^^^^^^^^^^^^
File "C:\Users\Ot903056\PycharmProjects\PublicServer\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 0xd6 in position 84: invalid continuation byte
BUT!
conn = psycopg2.connect( host="127.0.0.1", port="5432") Successfully connected!
conn = psycopg2.connect( host="locationhost", port="5432") # not input database
Traceback (most recent call last):
File "C:\Users\Ot903056\PycharmProjects\PublicServer\test.py", line 4, in
conn = psycopg2.connect(
^^^^^^^^^^^^^^^^^
File "C:\Users\Ot903056\PycharmProjects\PublicServer\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 0xd6 in position 61: invalid continuation byte
The error message does not match the actual situation
The text was updated successfully, but these errors were encountered: