Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 4d8edcf

Browse files
Yomguitherealboogheta
authored andcommitted
Using certifi to find ssl cert for nontrivial python installations
1 parent c23229d commit 4d8edcf

File tree

6 files changed

+12
-3
lines changed

6 files changed

+12
-3
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
run: |
3030
python -m pip install -U pip
3131
python -m pip install -U setuptools twine wheel
32+
python -m pip install -r requirements.txt
3233
3334
- name: Build package
3435
run: |

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
run: |
3939
python -m pip install -U pip
4040
python -m pip install -U pytest pytest-cov mock
41+
python -m pip install -r requirements.txt
4142
4243
- name: Tests
4344
shell: bash

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
certifi

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def local_scheme(version):
4747
zip_safe=True,
4848
use_scm_version={"local_scheme": local_scheme},
4949
setup_requires=["setuptools_scm"],
50+
install_requires=["certifi"],
5051
entry_points="""
5152
# -*- Entry points: -*-
5253
[console_scripts]

twitter/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import urllib2 as urllib_request
1818
import urllib2 as urllib_error
1919

20+
import certifi
21+
2022
try:
2123
from cStringIO import StringIO
2224
except ImportError:
@@ -369,7 +371,7 @@ def __call__(self, **kwargs):
369371
return self._handle_response(req, uri, arg_data, _timeout)
370372

371373
def _handle_response(self, req, uri, arg_data, _timeout=None):
372-
kwargs = {}
374+
kwargs = {'cafile': certifi.where()}
373375
if _timeout:
374376
kwargs['timeout'] = _timeout
375377
try:

twitter/stream.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
else:
1717
import urllib2 as urllib_request
1818
import urllib2 as urllib_error
19+
20+
import certifi
21+
1922
import json
2023
from ssl import SSLError
2124
import socket
2225
import codecs
23-
import sys, select, time
26+
import select, time
2427

2528
from .api import TwitterCall, wrap_response, TwitterHTTPError
2629

@@ -218,7 +221,7 @@ def handle_stream_response(req, uri, arg_data, block, timeout, heartbeat_timeout
218221
context = None
219222
if not verify_context and _HAVE_SSL:
220223
context = ssl._create_unverified_context()
221-
handle = urllib_request.urlopen(req, context=context)
224+
handle = urllib_request.urlopen(req, context=context, cafile=certifi.where())
222225
except urllib_error.HTTPError as e:
223226
raise TwitterHTTPError(e, uri, 'json', arg_data)
224227
return iter(TwitterJSONIter(handle, uri, arg_data, block, timeout, heartbeat_timeout))

0 commit comments

Comments
 (0)