I want to send post request to some app.
This code does not work properly with cyrillic strings (user saved with wrong characters):
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)
I run netcat
to inspect raw request:
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"}
I also check with curl
(it works fine):
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":"Петров"}
So I think that problem with unicode encoding (server app documentation is weak and I have no access sources).
How to bring the request to the second form?
Python 3.7.3