Python URL编码日语字符

Python URL编码日语字符,python,Python,我将如何对以下内容进行URL编码?我当前所做的操作会抛出一个键错误 episode_title = 'ザ・ロック(日本語吹替版)' try: qs = urllib.quote(episode_title) except: qs = urllib.quote(episode_title.encode('utf8')) Traceback (most recent call last): KeyError: u'\u30b6' 可能会在字符串中添加一个解码('utf-8')

我将如何对以下内容进行URL编码?我当前所做的操作会抛出一个
键错误

episode_title = 'ザ・ロック(日本語吹替版)'
try:
    qs = urllib.quote(episode_title)
except:
    qs = urllib.quote(episode_title.encode('utf8'))

Traceback (most recent call last):
  KeyError: u'\u30b6'
可能会在字符串中添加一个
解码('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
结果:
注:我使用的是iPython,您的代码运行良好。也许您可以切换到另一个编辑器。

您使用的是哪种python版本?请参阅--TL;DR:urllib.urlencode Unicode字符串的utf-8编码。如果您使用Python2进行此操作,请执行
eposion\u title=u'ザ・ロック(日本語吹替版)'
使用该
插曲\u title
unicode字符串(即异常块中的语句)的编码结果。尝试将unicode添加到字符串:
插曲\u title=u'ザ・ロック(日本語吹替版)',并执行:
qs=urllib.quote(插曲标题.encode('utf8'))
,看看这是否有效
%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%29