Skip to content
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.ProgrammingError: can't adapt type 'IPv4Address' #1574

Open
billchenchina opened this issue May 11, 2023 · 1 comment
Open

psycopg2.ProgrammingError: can't adapt type 'IPv4Address' #1574

billchenchina opened this issue May 11, 2023 · 1 comment

Comments

@billchenchina
Copy link

billchenchina commented May 11, 2023

Please complete the following information:

  • OS: Debian GNU/Linux 12
  • Psycopg version: psycopg2==2.9.6
  • Python version: 3.11.2
  • PostgreSQL version: 15
  • pip version: 23.0.1

Describe the bug
Please let us know:

1: what you did

import ipaddress
from datetime import datetime
import psycopg2
import psycopg2.extras
psycopg2.extras.register_ipaddress()
# blabla
with conn.cursor() as cur:
    cur.execute(
        r'INSERT INTO tablename (inet, timestamp) VALUES (%s, %s)',
        (ipaddress.ip_address('127.0.0.1'), datetime.now())
    )

2: what you expected to happen

ipaddress inserted into inet

3: what happened instead

psycopg2.ProgrammingError: can't adapt type 'IPv4Address'

for t in [ipaddress.IPv4Interface, ipaddress.IPv6Interface,

@dvarrazzo
Copy link
Member

Weird. I have no idea why this function only handles Network and Interface address.

Psycopg 3 does it better.

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

No branches or pull requests

2 participants