From 7e28e30b76d5a1d8fe22d0199ef1b1101728d4bb Mon Sep 17 00:00:00 2001 From: Peter Knowles Date: Thu, 19 Sep 2024 12:19:14 +0100 Subject: [PATCH] Use Mozilla certificates in urlopen() --- pubchempy.py | 5 ++++- requirements/common.txt | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pubchempy.py b/pubchempy.py index 8de112f..ce18de0 100644 --- a/pubchempy.py +++ b/pubchempy.py @@ -14,10 +14,12 @@ import json import logging import os +import ssl import sys import time import warnings import binascii +import certifi try: from urllib.error import HTTPError @@ -268,7 +270,8 @@ def request(identifier, namespace='cid', domain='compound', operation=None, outp try: log.debug('Request URL: %s', apiurl) log.debug('Request data: %s', postdata) - response = urlopen(apiurl, postdata) + context = ssl.create_default_context(cafile=certifi.where()) + response = urlopen(apiurl, postdata, context=context) return response except HTTPError as e: raise PubChemHTTPError(e) diff --git a/requirements/common.txt b/requirements/common.txt index 5bdd187..a0b8c8a 100644 --- a/requirements/common.txt +++ b/requirements/common.txt @@ -1 +1,2 @@ pandas>=0.16.2 +certifi>=2024.8.30