Asked  7 Months ago    Answers:  5   Viewed   57 times

Here's my code:

import urllib2.request

response = urllib2.urlopen("http://www.google.com")
html = response.read()
print(html)

Any help?

 Answers

16

As stated in the urllib2 documentation:

The urllib2 module has been split across several modules in Python 3 named urllib.request and urllib.error. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.

So you should instead be saying

from urllib.request import urlopen
html = urlopen("http://www.google.com/").read()
print(html)

Your current, now-edited code sample is incorrect because you are saying urllib.urlopen("http://www.google.com/") instead of just urlopen("http://www.google.com/").

Tuesday, June 1, 2021
 
steros
answered 7 Months ago
68

Support for Python 3 was added in NumPy version 1.5.0, so to begin with, you must download/install a newer version of NumPy.

Or simply using pip:

python3 -m pip install numpy
Thursday, June 3, 2021
 
Francisunoxx
answered 7 Months ago
22

response.read() returns an instance of bytes while StringIO is an in-memory stream for text only. Use BytesIO instead.

From What's new in Python 3.0 - Text Vs. Data Instead Of Unicode Vs. 8-bit

The StringIO and cStringIO modules are gone. Instead, import the io module and use io.StringIO or io.BytesIO for text and data respectively.

Monday, June 21, 2021
 
nhunston
answered 6 Months ago
38

Try with lower case, import is case sensitive and it's as below:

import quandl

Did you install with pip? If so ensure quandl is among the listed installed modules with

pip list

Otherwise try

help('modules')

To make sure it was installed properly. If you don't see quandl listed , try to reinstall.

Tuesday, August 3, 2021
 
Jeremy
answered 5 Months ago
58

use the following to convert to a timestamp in python 2

int((mod_time.mktime(first_run.timetuple())+first_run.microsecond/1000000.0))

Sunday, August 22, 2021
 
waylaidwanderer
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share