Skip to content

Commit a4cfef1

Browse files
author
Felix Kerekes
committed
Use http_requests instead of requests
1 parent b15aa1c commit a4cfef1

File tree

7 files changed

+33
-33
lines changed

7 files changed

+33
-33
lines changed

plotly/graph_reference.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import re
1111
from pkg_resources import resource_string
1212

13-
import requests
13+
import http_requests
1414
import six
1515

1616
from plotly import files, utils
@@ -89,10 +89,10 @@ def get_graph_reference():
8989
GRAPH_REFERENCE_PATH, sha1)
9090

9191
try:
92-
response = requests.get(graph_reference_url,
92+
response = http_requests.get(graph_reference_url,
9393
timeout=GRAPH_REFERENCE_DOWNLOAD_TIMEOUT)
9494
response.raise_for_status()
95-
except requests.exceptions.RequestException:
95+
except http_requests.exceptions.RequestException:
9696
if not graph_reference:
9797
path = os.path.join('graph_reference', 'default-schema.json')
9898
s = resource_string('plotly', path).decode('utf-8')

plotly/plotly/plotly.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
import os
2323
import warnings
2424

25-
import requests
25+
import http_requests
2626
import six
2727
import six.moves
2828

29-
from requests.auth import HTTPBasicAuth
29+
from http_requests.auth import HTTPBasicAuth
3030

3131
from plotly import exceptions, tools, utils, version, files
3232
from plotly.plotly import chunked_requests
@@ -384,7 +384,7 @@ def get_figure(file_owner_or_url, file_id=None, raw=False):
384384
raise exceptions.PlotlyError(
385385
"The 'file_id' argument must be a non-negative number."
386386
)
387-
response = requests.get(plotly_rest_url + resource,
387+
response = http_requests.get(plotly_rest_url + resource,
388388
headers=headers,
389389
verify=get_config()['plotly_ssl_verification'])
390390
if response.status_code == 200:
@@ -678,7 +678,7 @@ def get(figure_or_data, format='png', width=None, height=None, scale=None):
678678
payload['scale'] = scale
679679
url = _api_v2.api_url('images/')
680680

681-
res = requests.post(
681+
res = http_requests.post(
682682
url, data=json.dumps(payload, cls=utils.PlotlyJSONEncoder),
683683
headers=headers, verify=get_config()['plotly_ssl_verification'],
684684
)
@@ -831,7 +831,7 @@ def mkdirs(cls, folder_path):
831831

832832
url = _api_v2.api_url('folders')
833833

834-
res = requests.post(url, data=payload, headers=_api_v2.headers(),
834+
res = http_requests.post(url, data=payload, headers=_api_v2.headers(),
835835
verify=get_config()['plotly_ssl_verification'])
836836

837837
_api_v2.response_handler(res)
@@ -953,7 +953,7 @@ def upload(cls, grid, filename,
953953
payload['parent_path'] = parent_path
954954

955955
upload_url = _api_v2.api_url('grids')
956-
req = requests.post(upload_url, data=payload,
956+
req = http_requests.post(upload_url, data=payload,
957957
headers=_api_v2.headers(),
958958
verify=get_config()['plotly_ssl_verification'])
959959

@@ -1032,7 +1032,7 @@ def append_columns(cls, columns, grid=None, grid_url=None):
10321032

10331033
api_url = (_api_v2.api_url('grids') +
10341034
'/{grid_id}/col'.format(grid_id=grid_id))
1035-
res = requests.post(api_url, data=payload, headers=_api_v2.headers(),
1035+
res = http_requests.post(api_url, data=payload, headers=_api_v2.headers(),
10361036
verify=get_config()['plotly_ssl_verification'])
10371037
res = _api_v2.response_handler(res)
10381038

@@ -1108,7 +1108,7 @@ def append_rows(cls, rows, grid=None, grid_url=None):
11081108

11091109
api_url = (_api_v2.api_url('grids') +
11101110
'/{grid_id}/row'.format(grid_id=grid_id))
1111-
res = requests.post(api_url, data=payload, headers=_api_v2.headers(),
1111+
res = http_requests.post(api_url, data=payload, headers=_api_v2.headers(),
11121112
verify=get_config()['plotly_ssl_verification'])
11131113
_api_v2.response_handler(res)
11141114

@@ -1160,7 +1160,7 @@ def delete(cls, grid=None, grid_url=None):
11601160
"""
11611161
grid_id = _api_v2.parse_grid_id_args(grid, grid_url)
11621162
api_url = _api_v2.api_url('grids') + '/' + grid_id
1163-
res = requests.delete(api_url, headers=_api_v2.headers(),
1163+
res = http_requests.delete(api_url, headers=_api_v2.headers(),
11641164
verify=get_config()['plotly_ssl_verification'])
11651165
_api_v2.response_handler(res)
11661166

@@ -1228,7 +1228,7 @@ def upload(cls, meta, grid=None, grid_url=None):
12281228

12291229
api_url = _api_v2.api_url('grids') + '/{grid_id}'.format(grid_id=grid_id)
12301230

1231-
res = requests.patch(api_url, data=payload, headers=_api_v2.headers(),
1231+
res = http_requests.patch(api_url, data=payload, headers=_api_v2.headers(),
12321232
verify=get_config()['plotly_ssl_verification'])
12331233

12341234
return _api_v2.response_handler(res)
@@ -1284,7 +1284,7 @@ def parse_grid_id_args(cls, grid, grid_url):
12841284
def response_handler(cls, response):
12851285
try:
12861286
response.raise_for_status()
1287-
except requests.exceptions.HTTPError as requests_exception:
1287+
except http_requests.exceptions.HTTPError as requests_exception:
12881288
if (response.status_code == 404 and
12891289
get_config()['plotly_api_domain']
12901290
!= tools.get_config_defaults()['plotly_api_domain']):
@@ -1362,7 +1362,7 @@ def add_share_key_to_url(plot_url, attempt=0):
13621362
file_id = urlsplit.path.split('/')[2]
13631363

13641364
url = _api_v2.api_url("files/") + file_owner + ":" + file_id
1365-
new_response = requests.patch(url,
1365+
new_response = http_requests.patch(url,
13661366
headers=_api_v2.headers(),
13671367
data={"share_key_enabled":
13681368
"True",
@@ -1382,7 +1382,7 @@ def add_share_key_to_url(plot_url, attempt=0):
13821382
# check for access, and retry a couple of times if this is the case
13831383
# https://github.com/plotly/streambed/issues/4089
13841384
embed_url = plot_url.split('?')[0] + '.embed' + plot_url.split('?')[1]
1385-
access_res = requests.get(embed_url)
1385+
access_res = http_requests.get(embed_url)
13861386
if access_res.status_code == 404:
13871387
attempt += 1
13881388
if attempt == 5:
@@ -1422,7 +1422,7 @@ def _send_to_plotly(figure, **plot_options):
14221422

14231423
url = get_config()['plotly_domain'] + "/clientresp"
14241424

1425-
r = requests.post(url, data=payload,
1425+
r = http_requests.post(url, data=payload,
14261426
verify=get_config()['plotly_ssl_verification'])
14271427
r.raise_for_status()
14281428
r = json.loads(r.text)

plotly/tests/test_core/test_file/test_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88
import random
99
import string
10-
import requests
10+
import http_requests
1111
from unittest import TestCase
1212

1313
from nose.plugins.attrib import attr
@@ -49,7 +49,7 @@ def test_duplicate_folders(self):
4949
py.file_ops.mkdirs(first_folder)
5050
try:
5151
py.file_ops.mkdirs(first_folder)
52-
except requests.exceptions.RequestException as e:
52+
except http_requests.exceptions.RequestException as e:
5353
self.assertTrue(400 <= e.response.status_code < 500)
5454
else:
5555
self.fail('Expected this to fail!')

plotly/tests/test_core/test_get_requests/test_get_requests.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88
import copy
99
import json
10-
import requests
10+
import http_requests
1111

1212
import six
1313
from nose.plugins.attrib import attr
@@ -35,7 +35,7 @@ def test_user_does_not_exist():
3535
hd['plotly-username'] = username
3636
hd['plotly-apikey'] = api_key
3737
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
38-
response = requests.get(server + resource, headers=hd)
38+
response = http_requests.get(server + resource, headers=hd)
3939
if six.PY3:
4040
content = json.loads(response.content.decode('unicode_escape'))
4141
else:
@@ -58,7 +58,7 @@ def test_file_does_not_exist():
5858
hd['plotly-username'] = username
5959
hd['plotly-apikey'] = api_key
6060
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
61-
response = requests.get(server + resource, headers=hd)
61+
response = http_requests.get(server + resource, headers=hd)
6262
if six.PY3:
6363
content = json.loads(response.content.decode('unicode_escape'))
6464
else:
@@ -80,7 +80,7 @@ def test_wrong_api_key(): # TODO: does this test the right thing?
8080
hd['plotly-username'] = username
8181
hd['plotly-apikey'] = api_key
8282
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
83-
response = requests.get(server + resource, headers=hd)
83+
response = http_requests.get(server + resource, headers=hd)
8484
assert response.status_code == 401
8585
# TODO: check error message?
8686

@@ -98,7 +98,7 @@ def test_private_permission_defined():
9898
hd['plotly-username'] = username
9999
hd['plotly-apikey'] = api_key
100100
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
101-
response = requests.get(server + resource, headers=hd)
101+
response = http_requests.get(server + resource, headers=hd)
102102
if six.PY3:
103103
content = json.loads(response.content.decode('unicode_escape'))
104104
else:
@@ -120,7 +120,7 @@ def test_missing_headers():
120120
for header in headers:
121121
hd = copy.copy(default_headers)
122122
del hd[header]
123-
response = requests.get(server + resource, headers=hd)
123+
response = http_requests.get(server + resource, headers=hd)
124124
if six.PY3:
125125
content = json.loads(response.content.decode('unicode_escape'))
126126
else:
@@ -140,7 +140,7 @@ def test_valid_request():
140140
hd['plotly-username'] = username
141141
hd['plotly-apikey'] = api_key
142142
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
143-
response = requests.get(server + resource, headers=hd)
143+
response = http_requests.get(server + resource, headers=hd)
144144
if six.PY3:
145145
content = json.loads(response.content.decode('unicode_escape'))
146146
else:

plotly/tests/test_core/test_graph_reference/test_graph_reference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pkg_resources import resource_string
1010
from unittest import TestCase
1111

12-
import requests
12+
import http_requests
1313
import six
1414
from nose.plugins.attrib import attr
1515

@@ -64,7 +64,7 @@ def test_default_schema_is_up_to_date(self):
6464
api_domain = files.FILE_CONTENT[files.CONFIG_FILE]['plotly_api_domain']
6565
graph_reference_url = '{}{}?sha1'.format(api_domain,
6666
gr.GRAPH_REFERENCE_PATH)
67-
response = requests.get(graph_reference_url)
67+
response = http_requests.get(graph_reference_url)
6868
if six.PY3:
6969
content = str(response.content, encoding='utf-8')
7070
else:

plotly/tests/test_core/test_grid/test_grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import random
1111
import string
12-
import requests
12+
import http_requests
1313

1414
from nose import with_setup
1515
from nose.plugins.attrib import attr

plotly/tests/test_core/test_plotly/test_plot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from __future__ import absolute_import
99

1010
import json
11-
import requests
11+
import http_requests
1212
import six
1313

1414
from unittest import TestCase
@@ -184,7 +184,7 @@ def test_plot_url_response_given_sharing_key(self):
184184
# shareplot basically always gives a 200 if even if permission denied
185185
# embedplot returns an actual 404
186186
embed_url = plot_url.split('?')[0] + '.embed?' + plot_url.split('?')[1]
187-
response = requests.get(embed_url)
187+
response = http_requests.get(embed_url)
188188

189189
self.assertEqual(response.status_code, 200)
190190

@@ -201,7 +201,7 @@ def test_private_plot_response_with_and_without_share_key(self):
201201

202202
private_plot_url = py._send_to_plotly(self.simple_figure,
203203
**kwargs)['url']
204-
private_plot_response = requests.get(private_plot_url + ".json")
204+
private_plot_response = http_requests.get(private_plot_url + ".json")
205205

206206
# The json file of the private plot should be 404
207207
self.assertEqual(private_plot_response.status_code, 404)
@@ -210,7 +210,7 @@ def test_private_plot_response_with_and_without_share_key(self):
210210
urlsplit = six.moves.urllib.parse.urlparse(secret_plot_url)
211211
secret_plot_json_file = six.moves.urllib.parse.urljoin(
212212
urlsplit.geturl(), "?.json" + urlsplit.query)
213-
secret_plot_response = requests.get(secret_plot_json_file)
213+
secret_plot_response = http_requests.get(secret_plot_json_file)
214214

215215
# The json file of the secret plot should be 200
216216
self.assertTrue(secret_plot_response.status_code, 200)

0 commit comments

Comments
 (0)