46 lines
1.8 KiB
Python
46 lines
1.8 KiB
Python
import requests
|
|
from requests.adapters import HTTPAdapter, Retry
|
|
|
|
def get_requestOld(url, headers, params):
|
|
#try:
|
|
response = requests.get(url, headers=headers, params=params, verify=False)
|
|
response.raise_for_status()
|
|
# except requests.exceptions.HTTPError as errh:
|
|
# return "An Http Error occurred:" + repr(errh)
|
|
# except requests.exceptions.ConnectionError as errc:
|
|
# return "An Error Connecting to the API occurred:" + repr(errc)
|
|
# except requests.exceptions.Timeout as errt:
|
|
# return "A Timeout Error occurred:" + repr(errt)
|
|
# except requests.exceptions.RequestException as err:
|
|
# return "An Unknown Error occurred" + repr(err)
|
|
|
|
return response
|
|
|
|
def get_request(url, headers, params):
|
|
#try:
|
|
session = requests.Session()
|
|
retry = Retry(connect=3, backoff_factor=10)
|
|
adapter = HTTPAdapter(max_retries=retry)
|
|
session.mount('http://', adapter)
|
|
session.mount('https://', adapter)
|
|
|
|
#response = requests.get(url, headers=headers, params=params, verify=False)
|
|
response = session.get(url,headers=headers, params=params, verify=False)
|
|
|
|
response.raise_for_status()
|
|
# except requests.exceptions.HTTPError as errh:
|
|
# return "An Http Error occurred:" + repr(errh)
|
|
# except requests.exceptions.ConnectionError as errc:
|
|
# return "An Error Connecting to the API occurred:" + repr(errc)
|
|
# except requests.exceptions.Timeout as errt:
|
|
# return "A Timeout Error occurred:" + repr(errt)
|
|
# except requests.exceptions.RequestException as err:
|
|
# return "An Unknown Error occurred" + repr(err)
|
|
|
|
return response
|
|
|
|
def contains(list, filter):
|
|
for x in list:
|
|
if filter(x):
|
|
return True
|
|
return False |