I want to query SQL tables in databricks sqlwarehouse from local python setup. I created a new sqlwarehouse in azure databricks, used the python example inorder to query sample tables. After several minutes it fails with connection error. I had generated fresh token too.
I create a new workspace in Azure Databricks and used default sqlwarehouse instance. Now, I want to query sample tables from local python script. For this, I use the sample code provided by databricks inorder to query tables in Python. Following is the sample code from databricks itself:
from databricks import sql
import os
connection = sql.connect(
server_hostname="adb-2485588098372366.6.azuredatabricks.net",
http_path="/sql/1.0/warehouses/c62cc104e136a5bd",
access_token="dapif5d0c1ff887631d9ef0aea86d08446b3")
cursor = connection.cursor()
cursor.execute("SELECT * from range(10)")
print(cursor.fetchall())
cursor.close()
connection.close()
I this code from here:
I even generated fresh access token for this purpose. When I tested the script, it fails with connection error:
Traceback (most recent call last):
File "/Users/vishalgupta/PycharmProjects/ds-chat-app/src/test.py", line 199, in <module>
connection = sql.connect(
^^^^^^^^^^^^
File "/Users/vishalgupta/PycharmProjects/ds-chat-app/venv/lib/python3.11/site-packages/databricks/sql/__init__.py", line 84, in connect
return Connection(server_hostname, http_path, access_token, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/vishalgupta/PycharmProjects/ds-chat-app/venv/lib/python3.11/site-packages/databricks/sql/client.py", line 232, in __init__
self._open_session_resp = self.thrift_backend.open_session(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/vishalgupta/PycharmProjects/ds-chat-app/venv/lib/python3.11/site-packages/databricks/sql/thrift_backend.py", line 578, in open_session
response = self.make_request(self._client.OpenSession, open_session_req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/vishalgupta/PycharmProjects/ds-chat-app/venv/lib/python3.11/site-packages/databricks/sql/thrift_backend.py", line 507, in make_request
self._handle_request_error(error_info, attempt, elapsed)
File "/Users/vishalgupta/PycharmProjects/ds-chat-app/venv/lib/python3.11/site-packages/databricks/sql/thrift_backend.py", line 337, in _handle_request_error
raise network_request_error
databricks.sql.exc.RequestError: Error during request to server
Any tips or help is highly appreciated. Thank you.
