Skip to content

Commit 5dd162d

Browse files
authored
Merge pull request #1 from spicehq/corentin/cert-fix
Corentin/cert fix
2 parents 1f9e413 + 18d23ea commit 5dd162d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

snippet.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
import os
2+
from pathlib import Path
3+
import ssl
4+
import tempfile
5+
import urllib.request
6+
17
from pyarrow import flight
28

3-
client = flight.connect('grpc+tls://flight.spiceai.io')
49

10+
# Check for gRPC certificates
11+
if not (Path(Path.cwd().absolute().anchor) / 'usr' / 'share' / 'grpc' / 'roots.pem').exists():
12+
env_name = 'GRPC_DEFAULT_SSL_ROOTS_FILE_PATH'
13+
if env_name not in os.environ or not Path(os.environ[env_name]).exists():
14+
tls_root_certs = Path(tempfile.gettempdir()) / 'roots.pem'
15+
if not Path(tls_root_certs).exists():
16+
print('Downloading gRPC certificates')
17+
ssl._create_default_https_context = ssl._create_unverified_context
18+
urllib.request.urlretrieve('https://pki.google.com/roots.pem', str(tls_root_certs))
19+
os.environ[env_name] = str(tls_root_certs)
20+
21+
client = flight.connect('grpc+tls://flight.spiceai.io')
522
headers = [client.authenticate_basic_token('', 'API_KEY')]
623
options = flight.FlightCallOptions(headers=headers)
724

0 commit comments

Comments
 (0)