标签:direct except encode ssi redirect self card bsp cep
做接口的时候我们需要获取一个令牌,类似于token以及sessionid这样的签名,也可以说是一个令牌。
import urllib.request, urllib.parse, urllib.error import http.cookiejar class Cookie_login: def cookie_login(self): url = "http://192.168.110.85:8488/motorcade/ac/login" params = {"username":"17600151400","password":"aec60231d83fe6cf81444bc536596887,bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e","verifycode":"","redirectUrl":"../../home.html"} # 获取cookie postdata = urllib.parse.urlencode(params).encode() cookie_filename = ‘cookie.txt‘ cookie = http.cookiejar.MozillaCookieJar(cookie_filename) handler = urllib.request.HTTPCookieProcessor(cookie) opener = urllib.request.build_opener(handler) request = urllib.request.Request(url,postdata) try: response = opener.open(request) except urllib.error.URLError as e: print(e.code, ‘:‘, e.reason) # 保存cookie到cookie.txt中 cookie.save(ignore_discard=True, ignore_expires=True) # 把字典存放到session_id里面 session_id ={} for item in cookie: session_id[item.name]=item.value return session_id
标签:direct except encode ssi redirect self card bsp cep
原文地址:https://www.cnblogs.com/666666pingzi/p/10520478.html