Python Unicode UnicodeEncodeError [英] Python Unicode UnicodeEncodeError

查看:115
本文介绍了Python Unicode UnicodeEncodeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将UTF-8字符串转换为unicode时遇到问题。

I am having issues with trying to convert an UTF-8 string to unicode. I get the error.

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

我尝试在 try / 除了块,但是然后谷歌给我一个系统管理员错误是一行。
有人可以建议如何捕捉这个错误并继续。

I tried wrapping this in a try/except block but then google was giving me a system administrator error which was one line. Can someone suggest how to catch this error and continue.

干杯,约翰。

<
$ b

-- FULL ERROR --

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)


推荐答案

T他正确地

The correct solution is to do the following:

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

这篇关于Python Unicode UnicodeEncodeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆