Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Raises
------
ScopusHtmlError or HTTPError
If the status of the response is not ok.
ValueError
If the accept parameter is not one of the accepted values.
Returns
-------
resp : byte-like object
The content of the file, which needs to be serialized.
"""
# Get credentials and set request headers
key = config.get('Authentication', 'APIKey')
header = {
'X-ELS-APIKey': key,
'Accept': 'application/json',
'User-Agent': user_agent
}
if config.has_option('Authentication', 'InstToken'):
token = config.get('Authentication', 'InstToken')
header.update({'X-ELS-APIKey': key, 'X-ELS-Insttoken': token})
# Perform request
params.update(**kwds)
# If config.ini has a section as follows:
#
# [Proxy]
# https = protocol://server:port
#
# it uses a proxy as defined
If the accept parameter is not one of the accepted values.
Returns
-------
resp : byte-like object
The content of the file, which needs to be serialized.
"""
# Get credentials and set request headers
key = config.get('Authentication', 'APIKey')
header = {
'X-ELS-APIKey': key,
'Accept': 'application/json',
'User-Agent': user_agent
}
if config.has_option('Authentication', 'InstToken'):
token = config.get('Authentication', 'InstToken')
header.update({'X-ELS-APIKey': key, 'X-ELS-Insttoken': token})
# Perform request
params.update(**kwds)
# If config.ini has a section as follows:
#
# [Proxy]
# https = protocol://server:port
#
# it uses a proxy as defined
# see requests documentation for details
if config.has_section("Proxy"):
proxyDict = dict(config.items("Proxy"))
resp = requests.get(url, headers=header, proxies=proxyDict, params=params)
else:
resp = requests.get(url, headers=header, params=params)
# Handle error messages
def get_folder(api, view):
"""Auxiliary function to get the cache folder belonging to a an API
and eventually create the folder.
"""
if not config.has_section('Directories'):
create_config()
try:
folder = config.get('Directories', api)
except NoOptionError:
folder = DEFAULT_PATHS[api]
folder = os.path.join(folder, view or '')
if not os.path.exists(folder):
os.makedirs(folder)
return folder