【发布时间】:2026-02-01 05:45:01
【问题描述】:
我有一个在客户端使用 JS encodeURIComponent 编码的 unicode 字符串。
如果我在本地 Python 中使用以下内容,我会得到预期的结果:
>>> urllib.unquote("Foo%E2%84%A2%20Bar").decode("utf-8")
>>> u'Foo\u2122 Bar'
但是当我在 Google App Engine 中运行它时,我得到:
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 703, in __call__
handler.post(*groups)
File "/base/data/home/apps/s~kaon-log/2.357769827131038147/main.py", line 143, in post
path_uni = urllib.unquote(h.path).decode('utf-8')
File "/base/python_runtime/python_dist/lib/python2.5/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-5: ordinal not in range(128)
我仍在使用 Python 2.5,以防万一。我错过了什么?
【问题讨论】:
标签: python google-app-engine unicode character-encoding uri