修复 Python3 中 ImportError: cannot import name 'urlencode'
问题:
你的 python 3.x 解释器打印错误消息
importerror.txt
ImportError: cannot import name 'urlencode'解决方案
正如 Fred Foo 在 StackOverflow 上所述,Python3 中的 urlencode() 不在 urllib 模块中而在 urllib.parse 中。
因此你必须更改
fix_urlencode.py
from urllib import urlencodeto
fix_compat_urlencode.py
from urllib.parse import urlencode如果你打算为 Python2 和 Python3 编写代码,优先使用:
fix_compat_tryexcept.py
try:
from urllib import urlencode
except ImportError:
from urllib.parse import urlencodeCheck out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow