Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Connection Error - Query SQL database on databricks SQLwarehouse

$
0
0

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-XXXXXXXXXXXXXXX.X.azuredatabricks.net",        http_path="/sql/1.0/warehouses/XXXXXXXXXXX",        access_token="dapiXXXXXXXXXXXXXXXXXXXXXXXXXX")    cursor = connection.cursor()    cursor.execute("SELECT * from range(10)")    print(cursor.fetchall())    cursor.close()    connection.close()

I this code from here:

enter image description 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_errordatabricks.sql.exc.RequestError: Error during request to server

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>