我正在尝试通过尝试访问的API进行身份验证。我正在使用urllib.parse.urlencode对URL中的参数进行编码。我正在使用urllib.request.urlopen来获取内容。这应该从服务器返回3个值,例如:SID=AAAAAAAAAAALSID=BBBBBBBBBBBAUTH=CCCCCCCCCCC问题在于它仅返回第一个值和尾随的换行符。import urllib.requestimport urllib.parseEmailparamx = 'Email'Emailparam = Emailparamx.encode('utf-8')email = 'myemail@stackoverflow.com'email = email.encode('utf-8')Passwdparam = 'Passwd'Passwdparam = Passwdparam.encode('utf-8')password = 'hidden'password = password.encode('utf-8')Accounttypeparam = 'accountType'Accounttypeparam = Accounttypeparam.encode('utf-8')accounttype = 'GOOGLE'accounttype = accounttype.encode('utf-8')Serviceparam = 'service'Serviceparam = Serviceparam.encode('utf-8')service = 'adwords'service = service.encode('utf-8')url = 'https://accounts.google.com/ClientLogin?'urlen = url.encode('utf-8')data = [(Emailparamx, email), (Passwdparam, password), (Accounttypeparam, accounttype), (Serviceparam, service)]auth = ''dataurl = urllib.parse.urlencode(data)accessurl = (url + "%s" % dataurl)fh = urllib.request.urlopen(accessurl)equals = '='eqenc = equals.encode('utf-8')try: msg = fh.readline().split(eqenc) print (msg)然后味精打印[b'SID', b'AAAAAAAAAAAAAAAAA\n']我知道那是一些非常丑陋的代码,我使用Python大约一个星期了。任何帮助将不胜感激。
添加回答
举报
0/150
提交
取消