Python Requests中的未知编码:idna
我在用Python的Requests库,一切都运行得很好,但今天遇到了一个奇怪的错误:
[...]
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/requests/models.py", line 321, in full_url
netloc = netloc.encode('idna').decode('utf-8')
LookupError: unknown encoding: idna
有没有人知道可能出什么问题了?我用的是brew安装的Python 2.7.2。
1 个回答
26
试着在不同的地方添加:
import encodings.idna
来筛选出其他错误。我在把Python移植到一个新平台时也遇到了同样的问题。我们当时只支持部分库,而unicodedata
这个库缺失了,这导致导入idna模块失败。一旦我们移植了unicodedata
,这个错误就消失了。