def get_upload_domain(session, csrf=''):
""" return current cloud's upload domain url
it seems that csrf isn't necessary in session,
but forcing assert anyway to avoid possible future damage
"""
assert csrf is not None, 'no CSRF'
url = urljoin(CLOUD_URL, 'dispatcher?token=' + csrf)
try:
r = session.get(url, verify = VERIFY_SSL)
except Exception as e:
if LOGGER:
LOGGER.error('Get upload domain HTTP request error: {}'.format(e))
return None
if r.status_code == requests.codes.ok:
r_json = r.json()
return r_json['body']['upload'][0]['url']
elif LOGGER:
LOGGER.error('Upload domain request error. Check your connection. \
HTTP code: {}, msg: {}'.format(r.status_code, r.text))
return None
评论列表
文章目录