aws / amazon-redshift-python-driver

Redshift Python Connector. It supports Python Database API Specification v2.0.
Apache License 2.0
204 stars 76 forks source link

BugFix: Add support for both IPv4 and IPv6 connections #229

Open sparrovv opened 3 months ago

sparrovv commented 3 months ago

Description

At my company we started using VPN that only works over IPv6. Since that we started seeing below errors when connecting:

 08:57:16 Encountered an error: Database Error ('communication error', gaierror(8, 'nodename nor servname provided, or not known'))

Mainly played around and used chat GPT to make the above changes, so please let me know if they look fine with you.

Details

Motivation and Context

Testing

I've tried to connect both on new and old VPN and this snipped doesn't return an error anymore:

password = os.environ.get("REDSHIFT_PASSWORD")
user = os.environ.get("REDSHIFT_USER")
databse = os.environ.get("REDSHIFT_DATABASE")
host = os.environ.get("REDSHIFT_HOST")

conn = redshift_connector.connect(
    host=host,
    database=databse,
    user=user,
    password=password,
)

cursor: redshift_connector.Cursor = conn.cursor()
cursor.execute("select 1")
result: tuple = cursor.fetchall()
print(result)
cursor.close()

Screenshots (if appropriate)

Types of changes

Checklist