导入urllib时获取TypeError

时间:2014-06-09 18:13:07

标签: python python-2.7 ubuntu-12.04 urllib2 urllib

当我写下以下代码行时

import urllib

我收到此错误

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/urllib.py", line 26, in <module>
    import socket
  File "socket.py", line 2, in <module>
    s = socket.socket()
TypeError: 'module' object is not callable

在经历了关于SO的各种问题后,我尝试了这些:

from urllib import urlopen

(与上述相同的错误)

>>> urllib

错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'urllib' is not defined

>>> urllib.urlopen()

错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'urllib' is not defined

请帮忙。我尝试导入urllib2urllib3requests时出现类似错误。

1 个答案:

答案 0 :(得分:2)

您将文件命名为socket.py,隐藏了标准库socket模块。将其命名为其他。