1313from pythonkc_meetups .parsers import parse_event
1414from pythonkc_meetups .parsers import parse_member_from_rsvp
1515from pythonkc_meetups .parsers import parse_photo
16- import httplib2
1716import json
1817import mimeparse
18+ import requests
1919import urllib
2020
2121
@@ -196,15 +196,15 @@ def _http_get_json(self, url):
196196 * PythonKCMeetupsRateLimitExceeded
197197
198198 """
199- response , content = self ._http_get (url )
199+ response = self ._http_get (url )
200200
201- content_type = response ['content-type' ]
201+ content_type = response . headers ['content-type' ]
202202 parsed_mimetype = mimeparse .parse_mime_type (content_type )
203203 if parsed_mimetype [1 ] not in ('json' , 'javascript' ):
204204 raise PythonKCMeetupsNotJson (content_type )
205205
206206 try :
207- return json .loads (content )
207+ return json .loads (response . content )
208208 except ValueError as e :
209209 raise PythonKCMeetupsBadJson (e )
210210
@@ -220,8 +220,7 @@ def _http_get(self, url):
220220
221221 Returns
222222 -------
223- A tuple of response, content, where response is a dictionary of
224- response metadata (headers), and content is the entity body returned.
223+ An HTTP response, containing response headers and content.
225224
226225 Exceptions
227226 ----------
@@ -231,21 +230,20 @@ def _http_get(self, url):
231230
232231 """
233232 for try_number in range (self ._http_retries + 1 ):
234- client = httplib2 .Http (timeout = self ._http_timeout )
235- response , content = client .request (url , 'GET' )
236- if response .status == 200 :
237- return response , content
233+ response = requests .get (url , timeout = self ._http_timeout )
234+ if response .status_code == 200 :
235+ return response
238236
239237 if (try_number >= self ._http_retries or
240- response .status not in (408 , 500 , 502 , 503 , 504 )):
238+ response .status_code not in (408 , 500 , 502 , 503 , 504 )):
241239
242- if response .status >= 500 :
243- raise PythonKCMeetupsMeetupDown (response , content )
244- if response .status == 400 :
240+ if response .status_code >= 500 :
241+ raise PythonKCMeetupsMeetupDown (response , response . content )
242+ if response .status_code == 400 :
245243 try :
246244 data = json .loads (content )
247245 if data .get ('code' , None ) == 'limit' :
248246 raise PythonKCMeetupsRateLimitExceeded
249247 except : # Don't lose original error when JSON is bad
250248 pass
251- raise PythonKCMeetupsBadResponse (response , content )
249+ raise PythonKCMeetupsBadResponse (response , response . content )
0 commit comments