Skip to content

Commit 18d23ea

Browse files
author
Corentin
committed
Generic path for windows compatibility
* User temporary folder for certificate path
1 parent 6a10cf4 commit 18d23ea

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

snippet.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import os
22
from pathlib import Path
33
import ssl
4+
import tempfile
45
import urllib.request
56

67
from pyarrow import flight
78

89

910
# Check for gRPC certificates
10-
if not Path('/usr', 'share', 'grpc', 'roots.pem').exists():
11+
if not (Path(Path.cwd().absolute().anchor) / 'usr' / 'share' / 'grpc' / 'roots.pem').exists():
1112
env_name = 'GRPC_DEFAULT_SSL_ROOTS_FILE_PATH'
1213
if env_name not in os.environ or not Path(os.environ[env_name]).exists():
13-
tls_root_certs = './roots.pem'
14+
tls_root_certs = Path(tempfile.gettempdir()) / 'roots.pem'
1415
if not Path(tls_root_certs).exists():
1516
print('Downloading gRPC certificates')
1617
ssl._create_default_https_context = ssl._create_unverified_context
17-
urllib.request.urlretrieve('https://pki.google.com/roots.pem', tls_root_certs)
18-
os.environ[env_name] = tls_root_certs
18+
urllib.request.urlretrieve('https://pki.google.com/roots.pem', str(tls_root_certs))
19+
os.environ[env_name] = str(tls_root_certs)
1920

2021
client = flight.connect('grpc+tls://flight.spiceai.io')
2122
headers = [client.authenticate_basic_token('', 'API_KEY')]

0 commit comments

Comments
 (0)