-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathinteractive_oauth.py
More file actions
29 lines (23 loc) · 987 Bytes
/
interactive_oauth.py
File metadata and controls
29 lines (23 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from databricks import sql
import os
"""databricks-sql-connector supports user to machine OAuth login which means the
end user has to be present to login in a browser which will be popped up by the Python process.
Pre-requisites:
- You have installed a browser (Chrome, Firefox, Safari, Internet Explorer, etc) that will be
accessible on the machine for performing OAuth login.
This code does not persist the auth token. Hence after the Python process terminates the
end user will have to login again. See examples/persistent_oauth.py to learn about persisting the
token across script executions.
"""
with sql.connect(
server_hostname=os.getenv("DATABRICKS_SERVER_HOSTNAME"),
http_path=os.getenv("DATABRICKS_HTTP_PATH"),
) as connection:
for x in range(1, 100):
cursor = connection.cursor()
cursor.execute("SELECT 1+1")
result = cursor.fetchall()
for row in result:
print(row)
cursor.close()
connection.close()