Skip to content

Commit 49e4a1c

Browse files
committed
Replace httplib2 with requests
1 parent 2809d73 commit 49e4a1c

File tree

5 files changed

+48
-85
lines changed

5 files changed

+48
-85
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
six
2-
httplib2
2+
requests
33
socksipy-branch
44
PyJWT==1.4.2

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#
1414
# You need to have the setuptools module installed. Try reading the setuptools
1515
# documentation: http://pypi.python.org/pypi/setuptools
16-
REQUIRES = ["httplib2 >= 0.7", "six", "pytz", "PyJWT == 1.4.2"]
16+
REQUIRES = ["requests == 2.10.0", "six", "pytz", "PyJWT == 1.4.2"]
1717

1818
if sys.version_info < (2, 6):
1919
REQUIRES.append('simplejson')

twilio/http/http_client.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from requests import Request, Session
2+
3+
from twilio.http import HttpClient, get_cert_file
4+
from twilio.http.response import Response
5+
6+
7+
class TwilioHttpClient(HttpClient):
8+
def request(self, method, url, params=None, data=None, headers=None, auth=None, timeout=None,
9+
allow_redirects=False):
10+
"""
11+
General purpose HTTP client to make an HTTP request
12+
13+
:param str method: The HTTP method to use
14+
:param str url: The URL to request
15+
:param dict params: Query parameters to append to the URL
16+
:param dict data: Parameters to go in the body of the HTTP request
17+
:param dict headers: HTTP Headers to send with the request
18+
:param tuple auth: Basic Auth arguments
19+
:param float timeout: Socket/Read timeout for the request
20+
:param boolean allow_redirects: Whether or not to allow redirects
21+
22+
:return: An http response
23+
:rtype: A :class:`Response <twilio.rest.http.response.Response>` object
24+
25+
See the requests documentation for explanation of all these parameters
26+
"""
27+
session = Session()
28+
session.verify = get_cert_file()
29+
30+
request = Request(method.upper(), url, params=params, data=data, headers=headers, auth=auth)
31+
32+
prepped_request = session.prepare_request(request)
33+
response = session.send(
34+
prepped_request,
35+
allow_redirects=allow_redirects,
36+
timeout=timeout,
37+
)
38+
39+
return Response(int(response.status_code), response.content.decode('utf-8'))
40+
41+
42+

twilio/http/httplib2_client.py

Lines changed: 0 additions & 81 deletions
This file was deleted.

twilio/rest/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
import os
1010
import platform
11+
12+
from twilio.http.http_client import TwilioHttpClient
13+
1114
from twilio import __version__
1215
from twilio.exceptions import TwilioException
13-
from twilio.http.httplib2_client import Httplib2Client
1416
from twilio.rest.api import Api
1517
from twilio.rest.chat import Chat
1618
from twilio.rest.ip_messaging import IpMessaging
@@ -54,7 +56,7 @@ def __init__(self, username=None, password=None, account_sid=None,
5456

5557
self.auth = (self.username, self.password)
5658
""" :type : tuple(str, str) """
57-
self.http_client = http_client or Httplib2Client()
59+
self.http_client = http_client or TwilioHttpClient()
5860
""" :type : HttpClient """
5961

6062
# Domains

0 commit comments

Comments
 (0)