gpt4 book ai didi

Python 统一码 UnicodeEncodeError

转载 作者:太空宇宙 更新时间:2023-11-04 06:53:50 28 4
gpt4 key购买 nike

我在尝试将 UTF-8 字符串转换为 unicode 时遇到问题。我收到错误。

UnicodeEncodeError: 'ascii' codec can't encode characters in position 73-75: ordinal not in range(128)

我尝试将其包装在 try/except block 中,但随后谷歌给我一个系统管理员错误,这是一行。有人可以建议如何捕获此错误并继续。

干杯,约翰。

-- 完全错误 --

Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 501, in __call__
handler.get(*groups)
File "/Users/johnb/Sites/hurl/hurl.py", line 153, in get
self.redirect(url.long_url)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 371, in redirect
self.response.headers['Location'] = str(absolute_url)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 73-75: ordinal not in range(128)

最佳答案

正确的solution就是做以下事情:

self.response.headers['Location'] = urllib.quote(absolute_url.encode("utf-8"))

关于Python 统一码 UnicodeEncodeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1077564/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com