upload.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:mail.ru-uploader 作者: instefa 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号