import qiniu
import requests
import json
ak = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
sk = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
###构建七牛的验证对象
q = qiniu.Auth(ak,sk)
#获取该账号下的域名列表
getdomain_url = "http://api.qiniu.com/domain?marker=&limit="
getdomain_token = q.token_of_request(getdomain_url, body=None, content_type="application/json")
getdomain_headers = {'Authorization': 'QBox {0}'.format(getdomain_token), 'Content-Type': 'application/json'}
getdomain_result = requests.get(getdomain_url, headers=getdomain_headers)
getdomain_data = json.loads(getdomain_result.content)
domain_data = getdomain_data['domains']
for i in domain_data:
if i.get('operatingState') == 'offlined':
domain = i.get('name')
online_url = "http://api.qiniu.com/domain/%s/online" % domain
### 域名停用的链接,其他步骤一样
### offline_url = "http://api.qiniu.com/domain/%s/offline" % domain
online_token = q.token_of_request(online_url, body=None, content_type="application/json")
online_headers = {'Authorization': 'QBox {0}'.format(online_token),
'Content-Type': 'application/json'}
online_result = requests.post(online_url, headers=online_headers)
print(online_result, "200则是正常返回")