示例#1
0
def get_xml_error(text, func=None, args=None):
    try:
        error = getDictFromXml(text)
        if func is None:
            func = sys._getframe().f_back.f_code.co_name
        return '%s, Code=%s, RequestId=%s, Function=%s, Arguments=%s' % (
            error.get('Message'), error.get('Code'), error.get('RequestId'),
            func, args)
    except Exception:
        return text
示例#2
0
def _get_bucket_info(ak, sk, resource, host):
    date = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
    string_to_sign = 'GET\n\n\n%s\n%s' % (date, resource)
    signature = base64.b64encode(hmac.new(sk, string_to_sign, hashlib.sha1).digest())

    resp = requests.get(
            'https://%s%s' % (host, resource),
            headers={'Host': host,
                     'Date': date,
                     'Authorization': 'AWS %s:%s' % (ak, signature)},
            timeout=timeout,
            verify=cert_verify)
    if resp.status_code >= 300:
        func = sys._getframe().f_back.f_code.co_name
        raise HttpException(resp.status_code, resp.reason, get_xml_error(resp.text, func, args=resource))
    try:
        return getDictFromXml(resp.text)
    except Exception:
        return dict()