-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP "POST" request with UTF-8 non latin [feature] #1315
Comments
can you paste the full HTTP request settings here? |
Sure Url : https://www.bezeq.co.il/umbraco/api/FormWebApi/CheckAddress Method: POST Data: |
thanks, I can confirm this one. |
I'm having the same issue here. $ docker exec -it changedetection_io_app_1 bash
$ python3 -c "import requests; r = requests.post('http://httpbin.org/post', data='你好')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/requests/api.py", line 115, in post
return request("post", url, data=data, json=json, **kwargs)
File "/usr/local/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/requests/sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/requests/sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
File "/usr/local/requests/adapters.py", line 667, in send
resp = conn.urlopen(
File "/usr/local/urllib3/connectionpool.py", line 715, in urlopen
httplib_response = self._make_request(
File "/usr/local/urllib3/connectionpool.py", line 416, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/urllib3/connection.py", line 244, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "/usr/local/lib/python3.10/http/client.py", line 1283, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.10/http/client.py", line 1328, in _send_request
body = _encode(body, 'body')
File "/usr/local/lib/python3.10/http/client.py", line 166, in _encode
raise UnicodeEncodeError(
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1: Body ('你好') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.
--
ISO-8859-1 is well known as https://docs.python.org/3/library/http.client.html#http.client.HTTPConnection.request |
Possible solution r = requests.request(method=request_method,
- data=request_body,
+ data=request_body.encode('utf-8') if type(request_body) is str else request_body,
url=url,
headers=request_headers,
timeout=timeout,
proxies=proxies,
verify=False) |
I'm trying to post a request with UTF-8 chars
failing because latin-1 is used
couldn't find where to change it
'latin-1' codec can't encode characters in position 57-63: Body ('בדיקה') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.
The text was updated successfully, but these errors were encountered: