1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| import requests import json import sys
def login(username,password): url = "https://console.upyun.com/accounts/signin/"
payload = {"username":username,"password":password} headers = { 'Accept': "application/json, text/plain, */*", 'Accept-Encoding': "gzip, deflate, br", 'Accept-Language': "zh-CN,zh;q=0.9,en;q=0.8", 'Cache-Control': "no-cache", 'Connection': "keep-alive", 'Content-Length': "56", 'Content-Type': "application/json", 'DNT': "1", 'Host': "console.upyun.com", 'Origin': "https://console.upyun.com", 'Pragma': "no-cache", 'Referer': "https://console.upyun.com/login/", 'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36", 'cache-control': "no-cache", 'Postman-Token': "2d9bd080-b549-4c41-89ce-0b011f344a3f" }
response = requests.request("POST", url, data=json.dumps(payload), headers=headers)
if response.status_code == 200: return response.cookies
def purge_cdn(cookie,purge_url): url = "https://console.upyun.com/api/purge/"
payload = {"urls":purge_url} headers = { 'Accept': "application/json, text/plain, */*", 'Accept-Encoding': "gzip, deflate, br", 'Accept-Language': "zh-CN,zh;q=0.9,en;q=0.8", 'Cache-Control': "no-cache", 'Connection': "keep-alive", 'Content-Length': "28", 'Content-Type': "application/json", 'DNT': "1", 'Host': "console.upyun.com", 'Origin': "https://console.upyun.com", 'Pragma': "no-cache", 'Referer': "https://console.upyun.com/purge/purge_url/", 'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36", 'cache-control': "no-cache", }
response = requests_session.post(url, data=json.dumps(payload), headers=headers,cookies=cookie)
json_format = json.dumps(response.json()["data"], sort_keys=True, indent=4, separators=(',', ':')) print(json_format)
if __name__ == '__main__': username = "" password = ""
cookie = login(username,password) requests_session = requests.Session() purge_url = sys.argv[1] purge_cdn(cookie,purge_url)
|