zoukankan      html  css  js  c++  java
  • 阿里云签名

    # -*- coding: utf-8 -*-
    import uuid
    from urllib import unquote,quote
    import time, datetime
    from hashlib import sha1
    import hmac
    import base64
    import urllib2
    import urllib
    import cookielib
    import json
    import httplib
    import re
    import requests
    import pytz
    #uuid='3D99B500-FED0-11E8-ADC2-43E0E4AD0724'
    import uuid
    
    uuid = uuid.uuid1()
    tz = pytz.timezone('utc')
    print tz
    now = datetime.datetime.now(tz)
    sdate = now.strftime("%Y-%m-%dT%H:%M:%SZ")
    print sdate
    sdate = quote(sdate)
    print sdate
    ydate = sdate
    sdate = sdate.replace('%', '%25')
    yunid='LTAIb9zHh7U0Us3e'
    yunsecret='VbG8qFvhNEfWzilgNh0IAdeqXyhua2'
    
    
    def _init(a,b):
    
        DescribeRegions=b
        regionid=a
        header='GET&%2F&'
        myurl="AccessKeyId=%s&Action=%s&Format=JSON&RegionId=%s&SignatureMethod=HMAC-SHA1&SignatureNonce=%s&SignatureVersion=1.0&TimeStamp=%s&Version=2014-05-26" % (yunid,DescribeRegions,regionid,uuid,ydate)
        print myurl
        myurl=quote(myurl)
        myurl=header+myurl
        myurl=myurl.encode('utf-8')
        print myurl
        my_sign = hmac.new('VbG8qFvhNEfWzilgNh0IAdeqXyhua2&', myurl, sha1).digest()
        my_sign = base64.b64encode(my_sign)
        print my_sign
        my_sign=my_sign.encode('utf-8')
        return my_sign
    mysign=_init('region1','DescribeRegions')
    head='http://ecs.aliyuncs.com/?'
    url='SignatureVersion=1.0&Format=JSON&TimeStamp=%s&RegionId=%s&AccessKeyId=%s&SignatureMethod=HMAC-SHA1&Version=2014-05-26&Signature=%s&Action=%s&SignatureNonce=%s'%(ydate,'region1',yunid,mysign,'DescribeRegions',uuid)
    myurl=head+url
    s=requests.session()
    print s.get(myurl).content
    
    mysign=_init('cn-hangzhou','DescribeInstances')
    url='SignatureVersion=1.0&Format=JSON&TimeStamp=%s&RegionId=%s&AccessKeyId=%s&SignatureMethod=HMAC-SHA1&Version=2014-05-26&Signature=%s&Action=%s&SignatureNonce=%s'%(ydate,'cn-hangzhou',yunid,mysign,'DescribeInstances',uuid)
    myurl=head+url
    s=requests.session()
    print s.get(myurl).content
  • 相关阅读:
    virtio前端驱动详解
    virtIO前后端notify机制详解
    virtio后端驱动详解
    centos7手动编译安装Libvirt常见问题
    手动编译安装Libvirt之后利用systemctl管理libvirtd服务
    android学习点滴一:android环境的搭建
    phpcms换域名细节
    apache配置中的小细节
    娱乐一下-加班的不归路
    qt5.3+vs2013乱码
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348933.html
Copyright © 2011-2022 走看看