我在尝试将UTF-8字符串转换为unicode时遇到了问题。我收到错误。Python Unicode UnicodeEncodeError
UnicodeEncodeError: 'ascii' codec can't encode characters in position 73-75: ordinal not in range(128)
我想在一个try
/except
块包裹这一点,但那么谷歌是给我这是一条线一个系统管理员的错误。 有人可以建议如何捕获此错误并继续。
干杯,约翰。
- 完整的错误 -
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)
比较遗憾的是没有工作。 这是我现在的代码。因为我调用self.redirect,字符串正在编码并导致错误,因为在这种情况下,URL实际上有一个“å”。如果发生此错误,那么我将网址写入页面,并使用META-REFRESH标记,让浏览器在几秒钟后重定向 self.redirect(url.long_url) – 2009-07-03 02:45:11
@zdmytriv:unicode(absolute_url)?不应该在某处提到UTF-8吗? – 2009-07-03 02:53:05