Srs
Srs

Reputation: 79

NameError: name 'urllib' is not defined TypeError:'module' object not callable

Trying to execute this code. But i get the above error.

from urllib.request import FancyURLopener
from urllib.request import urlopen
exam = urllib.request.urlopen("192.168.2.2")
    print(exam.read)
    exam.close()

I expect to open the provided IP address.

Upvotes: 3

Views: 1948

Answers (1)

Vignesh SP
Vignesh SP

Reputation: 446

from urllib.request import FancyURLopener
from urllib.request import urlopen
exam = urlopen("http://192.168.2.2")
print(exam.read)
exam.close()

Try using urlopen("url") rather than the full urllib.request.urlopen(url).

You need to add http or https on your URL to make this work. Also, check out python requests, a good alternative to urllib.

Upvotes: 2

Related Questions