#!/usr/bin/python3.5
#
import sys, requests
try:
host = sys.argv[1]
except IndexError:
sys.exit('Usage: {0} host'.format(sys.argv[0]))
user = 'root'
passwd = '123'
url = 'http://{0}/xcache/cacher/'.format(host)
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
'Referer':'http://{0}/xcache/cacher/'.format(host),
}
payload = {'type':'0', 'cacheid':'0', 'clearcache':'%E6%B8%85%E9%99%A4'}
result = requests.post(url, headers=headers, data=payload, auth=(user, passwd))
if result.status_code == 200:
print('clear cache success')
else:
print(result.status_code)
模拟清除xcache缓存,xcache使用的3.2.0版本。
参考文档:http://docs.python-requests.org/zh_CN/latest/user/quickstart.html
http://docs.python-requests.org/zh_CN/latest/user/authentication.html
转载于:https://blog.51cto.com/zzh0804/1891563