O'Reilly Forums: Chapter 2 Code - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Chapter 2 Code Can't import html data

#1 User is offline   SageJ 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 15-March 14

Posted 15 March 2014 - 08:25 PM

I've been all over the forums on here and have seem many issues with the chapter 2 code. I have tried all of the different urls and none of them work for me. I'm not able to go past page 40 because I can't import the raw html data. Any suggestions?

CODE
import urllib.request

page=urllib.request.urlopen("http://beans-r-us.appspot.com/prices.html")
text=page.read().decoder("utf8")

print (text)

ERROR
import urllib.request
ImportError: No module named request
0

#2 User is offline   Stroodle88 

  • New Member
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 06-October 13
  • Gender:Male
  • Location:Columbia River Gorge, USA
  • Interests:• Guitar
    • mountain biking
    • learning Python
    • digital trading-card games
    • karaoke

Posted 15 March 2014 - 09:26 PM

SageJ:

The error you're getting implies not that the URL is incorrect, but that whatever IDE you're using to write your Python code isn't recognizing the request method. I've just copied and pasted the code you pasted above into two different IDEs. In one, I was able to reproduce the error you posted above. In the other, the import function works. The error code you're seeing implies the IDE you're using can't find or doesn't recognize the request method.

You should try a version of IDLE to test your code. I'm using IDLE 3.3.3 without a problem using the URL you posted above. Let me know if you have any questions about what I've written.
0

#3 User is offline   paulbarry 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 306
  • Joined: 20-August 09

Posted 15 March 2014 - 11:54 PM

Stroodle88 is correct - this code works fine (after changing "decoder" to "decode") when executed in IDLE, as shown in the book.

--Paul.
0

#4 User is offline   SageJ 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 15-March 14

Posted 16 March 2014 - 09:12 AM

Thanks for the help. Now that I just wiped my cpu for a clean dev environment with only IDLE installed, the code works fine. Now to find an additional product key code for windows 8 on the cheap for a segregated partition for all my "messy" installs and explorations. Any suggestions as to how to handle this? It seems like a fairly sensible thing to keep a sterile dev. environment.
0

#5 User is offline   paulbarry 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 306
  • Joined: 20-August 09

Posted 17 March 2014 - 12:31 PM

I don't know anything about Windows 8 keys, and such. But, if you want to keep your development stuff away from your regular stuff, I'd suggest installing VirtualBox from Oracle on your computer (free download, and free to use). With it, you can create virtual PC's onto which you can install most anything. Once you have VirtualBox up-and-running, I'd suggest installing the latest version of Ubuntu Linux (free download, and free to use). Total cost to you: nothing (other than your time and the downloads, of course). You can then experiment with Python on Ubuntu to your heart's content - and, of course, Python 3 and IDLE3 come pre-installed. :-)

Hope this suggestion helps.... and glad to see your problem is solved.

--Paul.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users