脚本刷新阿里云cdn缓存

#!/usr/bin/env python
#coding=utf-8

import getopt
import sys
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcdn.request.v20180510.RefreshObjectCachesRequest import RefreshObjectCachesRequest

def main(argv):
try:
options, args = getopt.getopt(argv, “hu:t:”, [“help”, “url=”, “type=”])
except getopt.GetoptError:
sys.exit()
url=""
type=""
for option, value in options:
if option in ("-h", “–help”):
print(“help”)
if option in ("-u", “–url”):
url=value
print(“url is: {0}”.format(url))
if option in ("-t", “–type”):
type=value
print(“type is: {0}”.format(type))

print(“error args: {0}”.format(args))
if len(url)==0 or len(type)==0:
print(“parameter is error!”);
return;
client = AcsClient(‘你的akId’, ‘你的ak’, ‘cn-shenzhen’)

request = RefreshObjectCachesRequest()
request.set_accept_format(‘json’)

request.set_ObjectPath(url)
request.set_ObjectType(type)

try:
response = client.do_action_with_exception(request)
print(str(response, encoding=‘utf-8’))
except BaseException as ex:
print(“exception%s”%ex)

if name == ‘main’:
main(sys.argv[1:])
print(‘success’)

发布了8 篇原创文章 · 获赞 0 · 访问量 10

猜你喜欢

转载自blog.csdn.net/weixin_41813300/article/details/105063697