2 lv19980523 lv19980523 于 2017.08.29 12:46 提问

模拟登录时UnicodeEncodeError: 'latin-1'问题该如何解决?

  例如:

data =  urllib.parse.urlencode(values)
postdata = data.decode('utf-8')

req = requests.post(url,postdata,headers=headers)

  以下是源代码:

from urllib import request
from urllib import parse
import requests
import time

url = 'http://mail.163.com/'

post_url = 'https://dl.reg.163.com/l'

headers={
        'User-Agent' : 'Mozilla/5.0 (X11; Ubuntu; Linu…) Gecko/20100101 Firefox/55.0',
        'Host':'gzcp.127.net',
        'Accept-Language':'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
        'Accept-Encoding':'gzip, deflate',
        'Referer':url,
        'Connection':'keep-alive'
        }

time = int(time.time())
print(time)
values = {
        'un':'lv19980523@163.com',
        'pw':'WrNlN11lmXwrJkrg7UdNPH1u6FEMtRfddaDd16BbYxngoW6B04l2WgC8k0wlOkvRm6xFfU',
        'pd':'mail163',
        'l' :'0',
        'd' :'10',
        't' :time,
        'pkid':'CvViHzl',
        'domains'   :'163.com',
        'tk':'189b96b1fa4a797b184868be3793daf0',
        'pwdKeyUp':'1',
        'topURL':'http://mail.163.com/'
            }
data = parse.urlencode(values).encode('utf-8')

req = requests.post(post_url,data,headers=headers)

response = request.urlopen(req)

print(response)

2个回答

qq_23126581
qq_23126581   Rxr 2017.08.29 13:28
已采纳

encoding ='latin-1'

encoding ='utf-8'
你从代码中找找,有没有编码没有设置成UTF-8

lv19980523
lv19980523 好像就是在使用requests的post方法时出错了
3 个月之前 回复
lv19980523
lv19980523 没有啊
3 个月之前 回复
oyljerry
oyljerry   Ds   Rxr 2017.08.29 14:49

你不处理应该就可以直接发送了

 values = {
        'un':'lv19980523@163.com',
        'pw':'WrNlN11lmXwrJkrg7UdNPH1u6FEMtRfddaDd16BbYxngoW6B04l2WgC8k0wlOkvRm6xFfU',
        'pd':'mail163',
        'l' :'0',
        'd' :'10',
        't' :time,
        'pkid':'CvViHzl',
        'domains'   :'163.com',
        'tk':'189b96b1fa4a797b184868be3793daf0',
        'pwdKeyUp':'1',
        'topURL':'http://mail.163.com/'
            }

req = requests.post(post_url,values,headers=headers)
lv19980523
lv19980523 还是不行啊。。。快疯了都。。。
3 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片