#!/usr/bin/python3.5#import sys, requeststry: 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)
Simulation clears the XCache cache, which is used by the XCache 3.2.0 version.
Reference Document: Http://docs.python-requests.org/zh_CN/latest/user/quickstart.html
Http://docs.python-requests.org/zh_CN/latest/user/authentication.html
This article is from the "Technical essay" blog, please be sure to keep this source http://zzh0804.blog.51cto.com/10792368/1891563
Post request (Python) that requires auth authentication