Archit Verma
Archit Verma

Reputation: 1917

Getting TypeError while importing urllib

When I write the following line of code

import urllib

I get this error

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

After going through various questions on SO I tried these:

from urllib import urlopen

(Same error as above)

>>> urllib

Error:

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

>>> urllib.urlopen()

Error:

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

Please help. I get a similar error when I try to import urllib2, urllib3, requests.

Upvotes: 0

Views: 408

Answers (1)

user2357112
user2357112

Reputation: 280564

You named your file socket.py, hiding the standard library socket module. Name it something else.

Upvotes: 2

Related Questions