sqlitecloud / sqlitecloud-py

Python drivers for SQLite Cloud
https://sqlitecloud.io
4 stars 1 forks source link

ValueError: check_hostname requires server_hostname #11

Closed blackary closed 1 week ago

blackary commented 1 month ago
from sqlitecloud.client import SqliteCloudClient
from sqlitecloud.types import SqliteCloudAccount

# I get the same result either with a real string or a fake one
account = SqliteCloudAccount("sqlitecloud://user:pass@host.com:port/dbname?apikey=myapikey")
client = SqliteCloudClient(cloud_account=account)
conn = client.open_connection()
Traceback (most recent call last):
  File "/private/tmp/sc/test.py", line 6, in <module>
    conn = client.open_connection()
  File "/private/tmp/sc/.direnv/python-3.10/lib/python3.10/site-packages/sqlitecloud/client.py", line 58, in open_connection
    connection = self._driver.connect(
  File "/private/tmp/sc/.direnv/python-3.10/lib/python3.10/site-packages/sqlitecloud/driver.py", line 51, in connect
    sock = self._internal_connect(hostname, port, config)
  File "/private/tmp/sc/.direnv/python-3.10/lib/python3.10/site-packages/sqlitecloud/driver.py", line 129, in _internal_connect
    sock = context.wrap_socket(sock, server_hostname=hostname)
  File "/Users/zblackwood/.pyenv/versions/3.10.12/lib/python3.10/ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "/Users/zblackwood/.pyenv/versions/3.10.12/lib/python3.10/ssl.py", line 1028, in _create
    raise ValueError("check_hostname requires server_hostname")
ValueError: check_hostname requires server_hostname

python 3.10.12 sqlitecloud 0.77

danielebriggi commented 1 month ago

Thank you for the question blackary.

In SQLite Cloud, you can establish a connection with the database in two ways: by setting user/pass/hostname in the SqliteCloudAccount or by using the connection string.

Since you want to use the connection string, you can initialize the SqliteCloudClient like this:

from sqlitecloud.client import SqliteCloudClient

client = SqliteCloudClient(connection_str="sqlitecloud://user:pass@host.com:port/dbname?apikey=myapikey")
conn = client.open_connection()

result = client.exec_query("SELECT * FROM albums", conn)

print("First row album title: " + str(result.get_value(0, 1)))

client.disconnect(conn)

Let me know how it goes!

blackary commented 1 week ago

Excellent, thanks! I believe the old README suggested it was just the first argument, not a keyword argument, but that works well, as does the new method with the updated package.