Skip to content

Commit d29177d

Browse files
authored
Merge pull request #11 from blink1073/INTPYTHON-642
INTPYTHON-642 Ensure client certificates
2 parents db62ac1 + 624702c commit d29177d

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

pymongo_voyageai/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import io
2+
import ssl
23
import urllib.request
34
from typing import Any
45

6+
import certifi
57
from PIL import Image
68

79
from .document import ImageDocument
@@ -104,7 +106,8 @@ def url_to_images(
104106
storage.close()
105107
# For all other files, use the native download.
106108
if source is None:
107-
with urllib.request.urlopen(url) as response:
109+
ssl_context = ssl.create_default_context(cafile=certifi.where())
110+
with urllib.request.urlopen(url, context=ssl_context) as response:
108111
source = io.BytesIO(response.read())
109112

110113
if url.endswith(".parquet"):

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ classifiers = [
2929
]
3030
dependencies = [
3131
"boto3>=1.37.25",
32+
"certifi>=2025.4.26",
3233
"langchain-mongodb>=0.6.0",
3334
"pymongo>=4.12.0",
3435
"voyageai>=0.3.0",

tests/test_client_integration.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import os
2+
import ssl
23
import urllib.request
34
from collections.abc import Generator
45

6+
import certifi
57
import numpy as np
68
import pytest
79
from bson import ObjectId
@@ -82,7 +84,8 @@ def test_pdf_pages_storage(client: PyMongoVoyageAI):
8284
url = "https://www.fdrlibrary.org/documents/356632/390886/readingcopy.pdf"
8385
storage = client._storage
8486
object_name = f"{ObjectId()}.pdf"
85-
with urllib.request.urlopen(url) as response:
87+
ssl_context = ssl.create_default_context(cafile=certifi.where())
88+
with urllib.request.urlopen(url, context=ssl_context) as response:
8689
storage.client.upload_fileobj(response, storage.root_location, object_name)
8790
url = f"s3://{storage.root_location}/{object_name}"
8891
images = client.url_to_images(url)
@@ -100,7 +103,8 @@ def test_pdf_pages_custom_storage(client: PyMongoVoyageAI):
100103
url = "https://www.fdrlibrary.org/documents/356632/390886/readingcopy.pdf"
101104
storage = client._storage
102105
object_name = f"{ObjectId()}.pdf"
103-
with urllib.request.urlopen(url) as response:
106+
ssl_context = ssl.create_default_context(cafile=certifi.where())
107+
with urllib.request.urlopen(url, context=ssl_context) as response:
104108
storage.client.upload_fileobj(response, storage.root_location, object_name)
105109
url = f"s3://{storage.root_location}/{object_name}"
106110
client._storage = MemoryStorage()

tests/test_client_unit.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import os
2+
import ssl
23
import tempfile
34
import urllib.request
45
from collections.abc import Generator
56
from pathlib import Path
67
from typing import Any
78

9+
import certifi
810
import pytest
911

1012
from pymongo_voyageai import MemoryStorage, PyMongoVoyageAI
@@ -89,7 +91,8 @@ def test_pdf_pages(client: PyMongoVoyageAI):
8991
def test_pdf_pages_storage(client: PyMongoVoyageAI):
9092
query = "The consequences of a dictator's peace"
9193
url = "https://www.fdrlibrary.org/documents/356632/390886/readingcopy.pdf"
92-
with urllib.request.urlopen(url) as response:
94+
ssl_context = ssl.create_default_context(cafile=certifi.where())
95+
with urllib.request.urlopen(url, context=ssl_context) as response:
9396
data = response.read()
9497
with tempfile.NamedTemporaryFile(suffix=".pdf") as fp:
9598
fp.write(data)

0 commit comments

Comments
 (0)