Skip to content

ipv6 address parsing error in postgresql conn string #838

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

Closed
sreenandan opened this issue Oct 14, 2021 · 0 comments · Fixed by #845
Closed

ipv6 address parsing error in postgresql conn string #838

sreenandan opened this issue Oct 14, 2021 · 0 comments · Fixed by #845

Comments

@sreenandan
Copy link

sreenandan commented Oct 14, 2021

For ipv6 addresses from https://www.postgresql.org/docs/10/libpq-connect.html we can use square brackets around ipv6 address, but it looks like there is a bug in parsing.

import asyncpg
import asyncio

async def run():
    conn = await asyncpg.connect(f"postgresql://postgres:patron@[fd74:ca9b:3a09:868c:0010:0009:0114:0067]:6321/postgres?sslmode=prefer")
    await conn.close()

asyncio.run(run())

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 568, in run_until_complete
    return future.result()
  File "<stdin>", line 2, in run
  File "/usr/local/lib/python3.7/site-packages/asyncpg/connection.py", line 1727, in connect
    max_cacheable_statement_size=max_cacheable_statement_size)
  File "/usr/local/lib/python3.7/site-packages/asyncpg/connect_utils.py", line 656, in _connect
    addrs, params, config = _parse_connect_arguments(timeout=timeout, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/asyncpg/connect_utils.py", line 497, in _parse_connect_arguments
    server_settings=server_settings)
  File "/usr/local/lib/python3.7/site-packages/asyncpg/connect_utils.py", line 237, in _parse_connect_dsn_and_args
    host, port = _parse_hostlist(dsn_hostspec, port, unquote=True)
  File "/usr/local/lib/python3.7/site-packages/asyncpg/connect_utils.py", line 197, in _parse_hostlist
    hostlist_ports.append(int(hostspec_port))
ValueError: invalid literal for int() with base 10: 'ca9b:3a09:868c:0010:0009:0114:0067]:6321'`



$ pip show asyncpg
Name: asyncpg
Version: 0.21.0
Summary: An asyncio PostgreSQL driver
Home-page: https://github.com/MagicStack/asyncpg
Author: MagicStack Inc
Author-email: [email protected]
License: Apache License, Version 2.0
Location: /usr/local/lib/python3.7/site-packages
Requires: 
Required-by: 

$ postgresql version 13

This works:

async def run():
    conn = await asyncpg.connect(
        user="postgres",
        password="patron",
        host="fd74:ca9b:3a09:868c:0010:0009:0114:0067",
        port=6321,
        database="postgres",
        ssl="prefer"
    )
    await conn.close()
elprans added a commit that referenced this issue Nov 7, 2021
Plain IPv6 addresses specified in square brackets in the connection URI
are now parsed correctly.

Fixes: #838.
elprans added a commit that referenced this issue Nov 7, 2021
Plain IPv6 addresses specified in square brackets in the connection URI
are now parsed correctly.

Fixes: #838.
elprans added a commit that referenced this issue Nov 8, 2021
Plain IPv6 addresses specified in square brackets in the connection URI
are now parsed correctly.

Fixes: #838.
elprans added a commit that referenced this issue Nov 8, 2021
Plain IPv6 addresses specified in square brackets in the connection URI
are now parsed correctly.

Fixes: #838.
elprans added a commit that referenced this issue Nov 16, 2021
Plain IPv6 addresses specified in square brackets in the connection URI
are now parsed correctly.

Fixes: #838.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant