#3772 UnicodeEncodeError: 'latin-1' codec can't encode characters in position 70-71: ordinal not in range(256)

2001:4bc9* Posted at: 3 hours ago 👁7

'latin-1' codec can't encode characters in position 70-71: ordinal not in range(256):
Traceback (most recent call last):
File "/home/elena/pyvideotrans/videotrans/util/ListenVoice.py", line 17, in run

tts.run(

File "/home/elena/pyvideotrans/videotrans/tts/__init__.py", line 319, in run

FreeAzureTTS(**kwargs).run()

File "/home/elena/pyvideotrans/videotrans/tts/_base.py", line 178, in run

raise self.error if isinstance(self.error, Exception) else RuntimeError(str(self.error))

File "/home/elena/pyvideotrans/.venv/lib/python3.10/site-packages/tenacity/__init__.py", line 480, in call

result = fn(*args, **kwargs)

File "/home/elena/pyvideotrans/videotrans/tts/_freeazure.py", line 92, in get_voice

endpoint = self.get_endpoint()

File "/home/elena/pyvideotrans/videotrans/tts/_freeazure.py", line 63, in get_endpoint

response = requests.post(ENDPOINT_URL, headers=headers,proxies=None)

File "/home/elena/pyvideotrans/.venv/lib/python3.10/site-packages/requests/api.py", line 115, in post

return request("post", url, data=data, json=json, **kwargs)

File "/home/elena/pyvideotrans/.venv/lib/python3.10/site-packages/requests/api.py", line 59, in request

return session.request(method=method, url=url, **kwargs)

File "/home/elena/pyvideotrans/.venv/lib/python3.10/site-packages/requests/sessions.py", line 589, in request

resp = self.send(prep, **send_kwargs)

File "/home/elena/pyvideotrans/.venv/lib/python3.10/site-packages/requests/sessions.py", line 703, in send

r = adapter.send(request, **kwargs)

File "/home/elena/pyvideotrans/.venv/lib/python3.10/site-packages/requests/adapters.py", line 644, in send

resp = conn.urlopen(

File "/home/elena/pyvideotrans/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 787, in urlopen

response = self._make_request(

File "/home/elena/pyvideotrans/.venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 493, in _make_request

conn.request(

File "/home/elena/pyvideotrans/.venv/lib/python3.10/site-packages/urllib3/connection.py", line 493, in request

self.putheader(header, value)

File "/home/elena/pyvideotrans/.venv/lib/python3.10/site-packages/urllib3/connection.py", line 407, in putheader

super().putheader(header, *values)

File "/home/elena/.local/share/uv/python/cpython-3.10-linux-x86_64-gnu/lib/python3.10/http/client.py", line 1256, in putheader

values[i] = one_value.encode('latin-1')

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 70-71: ordinal not in range(256)


=
system:Linux-6.18.12-200.fc43.x86_64-x86_64-with-glibc2.42
version:v3.97
frozen:False
language:en
root_dir:/home/elena/pyvideotrans
Python: 3.10.19 (main, Feb 3 2026, 22:54:15) [Clang 21.1.4 ]

1 Replies

This error is caused by non-ASCII characters (likely Chinese or other Unicode characters) in the HTTP request headers when using the FreeAzureTTS (Edge-TTS) channel. The underlying http.client library is trying to encode the header values using the 'latin-1' codec, which fails.

Solution Steps:

  1. Check and modify the TTS role/voice name: The most likely cause is that the selected "配音角色" (voice role) contains non-ASCII characters (e.g., Chinese names like "云希", "晓晓"). Change the voice role to one that uses only English/Latin characters.
  2. Check the target language setting: Ensure the "目标语言" (target language) is set correctly. For example, if you are translating to English, set the target language to "英语" (English) and then select a corresponding English voice role.
  3. Use a different TTS channel: If the issue persists, switch to a different TTS channel, such as "Edge-TTS(免费)" (Edge-TTS (free)), which is more stable and fully supports Unicode.
  4. Adjust advanced settings for Edge-TTS: If you are already using Edge-TTS and encounter this error, it might be due to a specific voice name. Try a different voice. Additionally, to prevent rate-limiting issues that can cause failures, configure the following in Menu -> Tools/Options -> Advanced Options -> [字幕配音调整]:

    • Set 并发配音线程数 (Concurrent dubbing threads) to 1.
    • Set 配音后暂停秒 (Pause seconds after dubbing) to 5 or 10.

If the problem continues after these steps:
The error trace points to the _freeazure.py module. This suggests an issue with the specific endpoint or header generation for the free Azure TTS service. As a workaround, using the standard "Edge-TTS" channel is recommended.

Please refer to the relevant documentation:

Post Your Reply
Open source and free maintenance is not easy. If this project is helpful to you, please consider making a small donation to help the project continue to maintain and update.

Related resource

Similar issues already exist