Skip to content

Psycopg cuts away part of IPv6 address #752

@stinovlas

Description

@stinovlas

Problem

MWE:

from psycopg import Connection
Connection.connect("postgresql://user:password@[2001:1488:fffe:20::229]:5432/dbname")

Output:

Traceback (most recent call last):
  File "/home/jmusilek/git/others/auctions/psycopg_mwe.py", line 3, in <module>
    Connection.connect("postgresql://user:password@[2001:1488:fffe:20::229]:5432/dbname")
  File "/home/jmusilek/.virtualenvs/auctions/lib/python3.12/site-packages/psycopg/connection.py", line 748, in connect
    raise last_ex.with_traceback(None)
psycopg.OperationalError: connection failed: 1488:fffe:20::229", port 5432 failed: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

As you can see from the traceback, psycopg tries to connect to 1488:fffe:20::229, not 2001:1488:fffe:20::229. The first part is cut off. This happens with all IPv6 addresses and also when I specify a hostname in conninfo, which is then resolved to an IPv6 address. This does not happen with IPv4 addresses.

Unfortunatelly, I wasn't able to track down where this happens.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions