python - 如何发送没有'u'字符的发布请求?[蟒蛇请求]
问题描述
我想将发布请求发送到某个应用程序。
此代码不适用于西里尔字符串(用户使用错误字符保存):
import requests
s = requests.Session()
d = {
'name': 'Вова',
'surname': 'Петров',
}
response = s.post('http://localhost:8899/app/user/', json=d)
print(response.status_code)
print(response.text)
我跑来netcat
检查原始请求:
nc -kl 8899
POST /accsrv/http/person/ HTTP/1.1
Host: localhost:8899
User-Agent: python-requests/2.22.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Length: 147
Content-Type: application/json
{"name": "\u0420\u2019\u0420\u0455\u0420\u0406\u0420\u00b0", "surname": "\u0420\u045f\u0420\u00b5\u0421\u201a\u0421\u0402\u0420\u0455\u0420\u0406"}
我还检查curl
(它工作正常):
curl -d '{"name":"Вова", "surname":"Петров"}' -H "Content-Type: application/json" -X POST http://localhost:8899/app/user/
POST /app/user/ HTTP/1.1
Host: localhost:8899
User-Agent: curl/7.64.0
Accept: */*
Content-Type: application/json
Content-Length: 45
{"name":"Вова", "surname":"Петров"}
所以我认为 unicode 编码的问题(服务器应用程序文档很弱,我没有访问源)。
如何将请求带到第二个表格?
Python 3.7.3
解决方案
推荐阅读
- iis - 服务帐号权限限制
- android - Android - drawable-dpi 图像没有拾取
- json - 如何在 Postgres 11 中聚合父母和孩子
- django - 有没有办法通过单击按钮将 Django 表单字段上的空白属性更改为 False?
- java - 将消息发送到 Azure 事件中心主题时添加到标头的垃圾值
- python - 气候学频率和持续时间
- bash - 如何 cd 进入选定目录以在循环(shell)中的每个目录中应用代码?
- java - 如何在 ImageView Android Studio 中设置过滤器属性
- elementor - Elementor AJAX 弹出窗口
- html - 带有复选框/单选框的 jQuery 表单验证