Skip to content

Commit

Permalink
Changed urllib to requests
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Jul 24, 2019
1 parent d568cfb commit f43eb17
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 12 deletions.
2 changes: 0 additions & 2 deletions chemistry_tools/Assay.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ def from_aid(cls, aid):
:param int aid: The PubChem Assay Identifier (AID).
"""
#record = json.loads(request(aid, 'aid', 'assay', 'description').read().decode())['PC_AssayContainer'][0]
print(json.loads(request(aid, 'aid', 'assay', 'description').content.decode()))
record = json.loads(request(aid, 'aid', 'assay', 'description').content.decode())['PC_AssayContainer'][0]
return cls(record)

Expand Down
2 changes: 0 additions & 2 deletions chemistry_tools/Compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ def from_cid(cls, cid, **kwargs):
:param int cid: The PubChem Compound Identifier (CID).
"""
#record = json.loads(request(cid, **kwargs).read().decode())['PC_Compounds'][0]
print(json.loads(request(cid, **kwargs).content.decode()))
record = json.loads(request(cid, **kwargs).content.decode())['PC_Compounds'][0]
return cls(record)

Expand Down
3 changes: 0 additions & 3 deletions chemistry_tools/Errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ class PubChemHTTPError(PubChemPyError):
"""Generic error class to handle all HTTP error codes."""

def __init__(self, e):
#print(self.code)
#self.code = e.code
self.code = e.status_code
self.msg = e.reason
try:
#self.msg += ': %s' % json.loads(e.read().decode())['Fault']['Details'][0]
self.msg += ': %s' % json.loads(e.content.decode())['Fault']['Details'][0]
except (ValueError, IndexError, KeyError):
pass
Expand Down
6 changes: 1 addition & 5 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@

def test_requests():
"""Test a variety of basic raw requests and ensure they don't return an error code."""
#assert request('c1ccccc1', 'smiles').getcode() == 200
assert request('c1ccccc1', 'smiles').status_code == 200
#assert request('DTP/NCI', 'sourceid', 'substance', '747285', 'SDF').getcode() == 200
assert request('DTP/NCI', 'sourceid', 'substance', '747285', 'SDF').status_code == 200
#assert request('coumarin', 'name', output='PNG', image_size='50x50').getcode() == 200
assert request('coumarin', 'name', output='PNG', image_size='50x50').status_code == 200


Expand All @@ -40,8 +37,7 @@ def test_listkey_requests():
def test_xref_request():
"""Test requests with xref inputs."""
response = request('US6187568B1', 'PatentID', 'substance', operation='sids', searchtype='xref')
#assert response.code == 200
assert response.statis_code == 200
assert response.status_code == 200
response2 = get_json('US6187568B1', 'PatentID', 'substance', operation='sids', searchtype='xref')
assert 'IdentifierList' in response2
assert 'SID' in response2['IdentifierList']
Expand Down

0 comments on commit f43eb17

Please sign in to comment.