I have problems with urllib2 in Python 2.71

0

I have this request:

import urllib2     
f = urllib2.urlopen('http://www.python.org/')
print f.read(100)

but when I run it in Python 2.7.1, I get the following error:

  

AttributeError: 'module' object has not attribute 'urlopen'

    
asked by Joshep Rodriguez 06.03.2017 в 23:41
source

1 answer

0

I think you're missing the Request:

import urllib2
r = urllib2.Request('https://www.python.org/')
u = urllib2.urlopen(r)
response = u.read()
    
answered by 15.03.2017 / 11:51
source