我将如何对以下内容进行编码?我目前正在做的是抛出一个KeyError。
episode_title = 'ザ・ロック(日本語吹替版)'
try:
qs = urllib.quote(episode_title)
except:
qs = urllib.quote(episode_title.encode('utf8'))
Traceback (most recent call last):
KeyError: u'\u30b6'发布于 2015-03-06 03:23:34
也许可以在字符串中添加一个decode('utf-8')。
import urllib
episode_title = "ザ・ロック(日本語吹替版)".decode('utf-8')
try:
qs = urllib.quote(episode_title)
except:
qs = urllib.quote(episode_title.encode('utf8'))
print qs结果:
%E3%82%B6%E3%83%BB%E3%83%AD%E3%83%83%E3%82%AF%EF%BC%88%E6%97%A5%E6%9C%AC%E8%AA%9E%E5%90%B9%E6%9B%BF%E7%89%88%29PS:我使用iPython__,您的代码运行良好。也许你可以换个编辑器。
https://stackoverflow.com/questions/28891759
复制相似问题