Skip to main content

Yundun Api Sdk For Python

Project description

云盾 api sdk for python

说明

  • 接口基地址: 'http://apiv4.yundun.cn/V4/';
  • 接口遵循RESTful,默认请求体json,接口默认返回json
  • app_id, app_secret 联系技术客服,先注册一个云盾的账号,用于申请绑定api身份

签名算法

  • 每次请求都签名,保证传输过程数据不被篡改
  • 客户端:sha256签名算法,将参数base64编码+app_secret用sha256签名,每次请求带上签名
  • 服务端:拿到参数用相同的算法签名,对比签名是否正确

sdk 使用说明

  • 环境:python >=3.5
  • 支持get/post/patch/put/delete方法
  • 参数说明
    • app_id 云盾分配的app_id
    • app_secert 云盾分配的app_secert, 用于签名数据
    • api_pre api前缀
    • user_id 当前使用者在云盾的用户ID
    • timeout 请求超时时间,默认10秒,请合理设置
  • 每次调用会返回三个参数:(原始字符串,解析后的json字典,错误字符串)
  • 注意事项 针对所有请求,uri与get参数是分离的,如 http://apiv4.yundun.com/api/V4/version?v=1, 调用时v=1参数,须通过query传递 raw, body, err = sdk.get('version', query={'v': 1})

使用

### 实例化 YdSdk
from ydsdk import YdSdk

sdk = YdSdk({
    "app_id": 'xxxxxxxxxxx',
    "app_secert": 'xxxxxxxxxxxxx', 
    "api_pre": "http://apiv4.yundun.comn/api/V4/",
    'user_id': 1, 
    "timeout": 30,
})

### get 方式请求数据
raw, jsonData, err = sdk.get('version')
print(raw, jsonData, err)

### post 方式请求数据
query    = {}
postData = {'domain_id': 1, 'status': 2}
raw, body, err = sdk.post('firewall.turn_status', postData = postData, query=query)
print(raw, jsonData, err)

### patch 方式请求数据
query    = {}
postData = {'domain_id': 1, 'status': 2}
raw, body, err = sdk.patch('firewall.turn_status', postData = postData, query=query)
if err != "":
    print("error: ", err)
else:
    print(raw, jsonData)

### put 方式请求数据
query    = {}
postData = {'domain_id': 1, 'status': 2}
raw, body, err = sdk.put('firewall.turn_status', postData = postData, query=query)
print(raw, jsonData, err)

### delete 方式请求数据
query    = {}
postData = {'domain_id': 1, 'status': 2}
raw, body, err = sdk.put('firewall.turn_status', postData = postData, query=query)
print(raw, jsonData, err)


### put方式请求数据
query    = {}
postData = {'domain_id': 1, 'status': 2}
raw, body, err = sdk.put('firewall.turn_status', postData = postData, query=query)
print(raw, jsonData, err)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ydsdk, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size ydsdk-0.1.2-py3-none-any.whl (6.4 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size ydsdk-0.1.2.tar.gz (4.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page