当我尝试跟随Python Wiki 的示例与URL编码有关:

>>> import urllib
>>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
>>> f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query", params)
>>> print f.read()

在第二行上引起了错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'urlencode'

我想念什么?

答案

urllib已经分裂了Python 3

urllib.urlencode()功能现在urllib.parse.urlencode(),,,,

urllib.urlopen()功能现在urllib.request.urlopen()

来自: stackoverflow.com