[关闭]
@upyun 2017-11-29T06:19:25.000000Z 字数 1066 阅读 921

零基础带你玩转存储 API

API:REST API FORM API

API文档地址:http://docs.upyun.com/api/

体验使用Python-SDK :https://github.com/upyun/python-sdk


步骤:1.制作签名 2.发起请求

基本信息:bucket:restapi007 operator:upyunapi password:upyun@xxx


鉴权认证头:

  1. Authorization: UPYUN <Operator>:<Signature>

签名计算:

  1. <Signature> = Base64 (HMAC-SHA1 (<Password>,
  2. <Method>&
  3. <URI>&
  4. <Date>&
  5. <Content-MD5>
  6. ))

Python 代码实现

  1. #!/usr/bin/env python
  2. #-*-coding:utf-8-*-
  3. import hashlib
  4. from hashlib import sha1
  5. import datetime
  6. import hmac
  7. import base64
  8. import requests
  9. #// 操作员信息
  10. operator="upyunapi"
  11. password_md5 = hashlib.md5("upyun@XXXX").hexdigest() #获取操作员密码的MD5值
  12. # // 参数信息
  13. gmdate = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')#获取GMT时间
  14. strings = 'PUT' + '&' + '/restapi007/test2017/test201666.html' + '&' + gmdate
  15. # //签名制作
  16. sign = base64.b64encode(hmac.new(password_md5,strings,sha1).digest())
  17. header = 'UPYUN ' + operator + ':' + sign
  18. url = "http://v0.api.upyun.com/restapi007/test2017/test201666.html"
  19. payload = "12345"
  20. headers = {
  21. 'date': gmdate,
  22. 'authorization': header
  23. }
  24. response = requests.request("PUT", url, data=payload, headers=headers)
  25. print(response.text)

利用 POSTMAN 提交请求

操作演示


利用抓包工具 Wireshank 抓包请求

操作演示


参考资料

廖雪峰
Request 模板
GMT时间获取

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注