Skip to content

Commit

Permalink
setting timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkittredge committed Oct 13, 2017
1 parent e9f545c commit 6c23125
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions calcbench/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'domain' : 'https://www.calcbench.com/{0}',
'ssl_verify' : True,
'session' : None,
'timeout' : 60 * 10, # ten minute content request timeout, by default
}


Expand All @@ -42,7 +43,8 @@ def _calcbench_session():
{'email' : user_name,
'strng' : password,
'rememberMe' : 'true'},
verify=_SESSION_STUFF['ssl_verify'])
verify=_SESSION_STUFF['ssl_verify'],
timeout=_SESSION_STUFF['timeout'])
r.raise_for_status()
if r.text != 'true':
raise ValueError('Incorrect Credentials, use the email and password you use to login to Calcbench.')
Expand All @@ -65,7 +67,8 @@ def _json_POST(end_point, payload):
response = _calcbench_session().post(url,
data=json.dumps(payload),
headers={'content-type' : 'application/json'},
verify=_SESSION_STUFF['ssl_verify'])
verify=_SESSION_STUFF['ssl_verify'],
timeout=_SESSION_STUFF['timeout'])
try:
response.raise_for_status()
except requests.exceptions.HTTPError as e:
Expand Down Expand Up @@ -479,7 +482,8 @@ def document_contents(blob_id, SEC_ID, SEC_URL=None):
response = _calcbench_session().get(url,
params=payload,
headers={'content-type': 'application/json'},
verify=_SESSION_STUFF['ssl_verify'])
verify=_SESSION_STUFF['ssl_verify'],
timeout=_SESSION_STUFF['timeout'])
response.raise_for_status()
return response.json()['blobs'][0]

Expand All @@ -489,7 +493,9 @@ def document_contents_by_network_id(network_id):
response = _calcbench_session().get(url,
params=payload,
headers={'content-type': 'application/json'},
verify=_SESSION_STUFF['ssl_verify'])
verify=_SESSION_STUFF['ssl_verify'],
timeout=_SESSION_STUFF['timeout'])

response.raise_for_status()
return response.json()['blobs'][0]

Expand Down Expand Up @@ -587,8 +593,8 @@ def document_types():


if __name__ == '__main__':
_rig_for_testing(domain='localhost')
#_rig_for_testing(domain='localhost')
GPS_commitments_and_contigencies = list(document_search(company_identifiers=['GPS'],
document_name='XCommitmentAndContingencies',
document_name='CommitmentAndContingencies',
year=2016, period=0))[0]
print(GPS_commitments_and_contigencies.get_contents())

0 comments on commit 6c23125

Please sign in to comment.