Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: name 'urllib' is not defined "

CODE:

import networkx as net
from urllib.request import urlopen
def read_lj_friends(g, name):
# fetch the friend-list from LiveJournal
response=urllib.urlopen('http://www.livejournal.com/misc/fdata.bml?user='+name)

ERROR:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'urllib' is not defined
like image 405
Amit Mishra Avatar asked Feb 18 '17 10:02

Amit Mishra


People also ask

How do you define Urllib?

Urllib package is the URL handling module for python. It is used to fetch URLs (Uniform Resource Locators). It uses the urlopen function and is able to fetch URLs using a variety of different protocols. Urllib is a package that collects several modules for working with URLs, such as: urllib.

Is Urllib built in Python 3?

The urllib module in Python 3 allows you access websites via your program. This opens up as many doors for your programs as the internet opens up for you. urllib in Python 3 is slightly different than urllib2 in Python 2, but they are mostly the same.


1 Answers

You've imported urlopen directly, so you should refer to it like that rather than via urllib:

response = urlopen('...')
like image 195
Daniel Roseman Avatar answered Sep 24 '22 12:09

Daniel Roseman