Could you please advise on how to resolve this encoding issue on your platform?

Hello Render Support Team,

I am experiencing a persistent UnicodeEncodeError in my Python Flask application when it handles Japanese characters. I have already taken several troubleshooting steps, but the problem remains.

Error: My application fetches order data (including Japanese names) from an external API and returns it as a JSON response. When doing so, it crashes with the following error:

UnicodeEncodeError: ‘latin-1’ codec can’t encode characters in position 7-17: ordinal not in range(256)
Full Traceback:

File “/opt/render/project/src/app.py”, line 265, in get_orders_from_base
response = requests.get(api_url, headers=headers, params=params)
File “/opt/render/project/src/.venv/lib/python3.11/site-packages/requests/api.py”, line 73, in get
return request(“get”, url, params=params, **kwargs)
File “/opt/render/project/src/.venv/lib/python3.11/site-packages/requests/api.py”, line 59, in request
return session.request(method=method, url=url, **kwargs)
File “/opt/render/project/src/.venv/lib/python3.11/site-packages/requests/sessions.py”, line 589, in request
resp = self.send(prep, **send_kwargs)
File “/opt/render/project/src/.venv/lib/python3.11/site-packages/requests/sessions.py”, line 703, in send
r = adapter.send(request, **kwargs)
File “/opt/render/project/src/.venv/lib/python3.11/site-packages/requests/adapters.py”, line 486, in send
resp = conn.urlopen(
File “/opt/render/project/src/.venv/lib/python3.11/site-packages/urllib3/connectionpool.py”, line 787, in urlopen
response = self._make_request(
File “/opt/render/project/src/.venv/lib/python3.11/site-packages/urllib3/connectionpool.py”, line 493, in _make_request
conn.request(
File “/opt/render/project/src/.venv/lib/python3.11/site-packages/urllib3/connection.py”, line 493, in request
self.putheader(header, value)
File “/opt/render/project/src/.venv/lib/python3.11/site-packages/urllib3/connection.py”, line 407, in putheader
super().putheader(header, *values)
File “/opt/render/project/python/Python-3.11.4/lib/python3.11/http/client.py”, line 1259, in putheader
values[i] = one_value.encode(‘latin-1’)
Troubleshooting Steps Already Taken:

Set environment variables: PYTHONIOENCODING=UTF-8 and PYTHON_VERSION=3.11.4.
Ensured all file I/O in the application code uses encoding=‘utf-8’.
Set the Flask response Content-Type header to application/json; charset=utf-8.
Manually encoded the JSON response body to UTF-8 bytes.
Forced the requests library response encoding to utf-8 before parsing.
Despite all these measures, the error persists deep inside the http.client library, which suggests an issue with the underlying OS locale or Python build environment on the Render instance.

Could you please advise on how to resolve this encoding issue on your platform? Is there a way to set the locale for the environment (e.g., to en_US.UTF-8 or C.UTF-8)?

My service name is baseobsapp.

Thank you for your help.