#!/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
本文出自 “技术随笔” 博客,请务必保留此出处http://zzh0804.blog.51cto.com/10792368/1891563
原文地址:http://zzh0804.blog.51cto.com/10792368/1891563