Skip to content

Commit 6ba4889

Browse files
author
Chris Park
committed
Updated make_request to use Requests
1 parent 8c9ce9e commit 6ba4889

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

rosette/api.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -569,24 +569,24 @@ def _make_request(self, op, url, data, headers):
569569
code = "unknownError"
570570
rdata = None
571571
response_headers = {}
572+
573+
request = requests.Request(op, url, data=data, headers=headers)
574+
prepared_request = request.prepare()
575+
session = requests.Session()
576+
572577
for i in range(self.num_retries + 1):
573578
try:
574-
self.http_connection.request(op, url, data, headers)
575-
response = self.http_connection.getresponse()
576-
status = response.status
577-
rdata = response.read()
578-
response_headers["responseHeaders"] = (
579-
dict(response.getheaders()))
579+
response = session.send(prepared_request)
580+
status = response.status_code
581+
rdata = response.content
582+
response_headers = {"responseHeaders": dict(response.headers)}
583+
580584
if status == 200:
581-
if not self.reuse_connection:
582-
self.http_connection.close()
583585
return rdata, status, response_headers
584586
if status == 429:
585587
code = status
586588
message = "{0} ({1})".format(rdata, i)
587589
time.sleep(self.connection_refresh_duration)
588-
self.http_connection.close()
589-
self._connect(parsedUrl)
590590
continue
591591
if rdata is not None:
592592
try:
@@ -600,9 +600,9 @@ def _make_request(self, op, url, data, headers):
600600
raise RosetteException(code, message, url)
601601
except:
602602
raise
603-
except (httplib.BadStatusLine, gaierror):
603+
except requests.exceptions.RequestException as e:
604604
raise RosetteException(
605-
"ConnectionError",
605+
e.message,
606606
"Unable to establish connection to the Rosette API server",
607607
url)
608608

0 commit comments

Comments
 (0)