python - IDNA nameprep 无效字符 u'\x94'

标签 python unicode encoding

我有一些使用 unicode 的工作网址并尝试应用 IDNA 编码

test = ur"http://example.com/%D0%94%D0%B8%D1%81%D0%BA%D0%BE%D0%BD%D1%82-%D1%82%D0%B0%D0%BA%D1%81%D0%B8.22219/"
url_unq = urllib.unquote(test)
print url_unq
print url_unq.encode("idna")

上面的代码失败并显示:

File "C:\Python25\lib\encodings\idna.py", line 38, in nameprep raise UnicodeError("Invalid character %r" % c) UnicodeError: Invalid character u'\x94'

我的编码有什么问题?

最佳答案

这是因为 \x94 无法在 IDNA 中进行编码 - 请参阅 RFC3454 :

0080-009F; [CONTROL CHARACTERS]

关于python - IDNA nameprep 无效字符 u'\x94',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9360635/

相关文章:

python - 文件未找到错误 : [Errno 2] No such file or directory + os.

python - 如何将 Python 中的所有 unicode 小写字符与正则表达式匹配?

mysql - 无法使用 ADO/ODBC 将重音字符写入 MySQL

swift - 如何检查字符串是否只包含拉丁字符?

python - BeautifulSoup find_all UnicodeEncodeError

drupal - 在 Drupal 中的文本中出现奇怪的字符...可能是编码问题,但如何解决

python - 从python中的字符串消息中提取括号 '[ ]'中指定的数据

python - 如何在不重新加载的情况下返回主页

python - 如何在 Reportlabs 中将内容继续到下一页 - Python

Python2 : Using . decode with errors ='replace' 仍然返回错误