Body ('上海') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8

在开发接口自动化框架时,遇到使用requests.post发送含有汉字的请求报错。错误信息提示body不是有效的Latin-1编码。解决方法是对请求的data进行UTF-8编码,如使用data.encode('utf-8'),以此避免编码问题。

在做接口自动化框架开发时,遇到调用requests.post方法的时候报错。
报错信息:

请求出错了'latin-1' codec can't encode characters in position 9-10: Body ('上海') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.
Traceback (most recent call last):
  File "D:/PythonStudyDemo/API_AUTO/run.py", line 11, in <module>
    run(test_data)
  File "D:/PythonStudyDemo/API_AUTO/run.py", line 7, in run
    res=HttpRequest().http_request(item["url"],item["data"],item['http_method'])
  File "D:\PythonStudyDemo\API_AUTO\tools\http_request.py", line 14, in http_request
    raise e
  File "D:\PythonStudyDemo\API_AUTO\tools\http_request.py", line 9, in http_request
    res = requests.post(url,data,cookies=cookie)
  File "C:\Users\32465\AppData\Local\Programs\Python\Python37-32\lib\site-package
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dance Wang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值