Python and the internet

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jun 2009
Posts: 28
Reputation: Your_mum is an unknown quantity at this point 
Solved Threads: 0
Your_mum Your_mum is offline Offline
Light Poster

Python and the internet

 
0
  #1
Jul 3rd, 2009
Right, so I looked at some python tutorials about interfacing with internet, but every time a use a code such as:
  1. import urllib
  2. pagetext = urllib.urlopen("http://www.python.org.html").read()
  3. print pagetext
It just comes up with a load of error messages.
how can i sort this
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,145
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 949
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Python and the internet

 
0
  #2
Jul 3rd, 2009
If you are using Python2 ...
  1. import urllib
  2. pagetext = urllib.urlopen("http://www.python.org").read()
  3. print pagetext
For Python3 use ...
  1. import urllib.request
  2. pagetext = urllib.request.urlopen("http://www.python.org").read()
  3. print(pagetext)
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 28
Reputation: Your_mum is an unknown quantity at this point 
Solved Threads: 0
Your_mum Your_mum is offline Offline
Light Poster

Re: Python and the internet

 
0
  #3
Jul 3rd, 2009
Using 2.5.4:
came up with
  1. Traceback (most recent call last):
  2. File "C:/Python25/urltest.py", line 2, in <module>
  3. pagetext = urllib.urlopen("http://www.python.org").read()
  4. File "C:\Python25\Lib\urllib.py", line 82, in urlopen
  5. return opener.open(url)
  6. File "C:\Python25\Lib\urllib.py", line 190, in open
  7. return getattr(self, name)(url)
  8. File "C:\Python25\Lib\urllib.py", line 325, in open_http
  9. h.endheaders()
  10. File "C:\Python25\lib\httplib.py", line 860, in endheaders
  11. self._send_output()
  12. File "C:\Python25\lib\httplib.py", line 732, in _send_output
  13. self.send(msg)
  14. File "C:\Python25\lib\httplib.py", line 699, in send
  15. self.connect()
  16. File "C:\Python25\lib\httplib.py", line 667, in connect
  17. socket.SOCK_STREAM):
  18. IOError: [Errno socket error] (11001, 'getaddrinfo failed')
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,145
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 949
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Python and the internet

 
0
  #4
Jul 3rd, 2009
Strange ...
  1. import urllib
  2. pagetext = urllib.urlopen("http://www.python.org").read()
  3. print pagetext
... works just fine with Python 2.5.4

You could try the improved version ...
  1. import urllib2
  2. pagetext = urllib2.urlopen("http://www.python.org").read()
  3. print pagetext
Last edited by vegaseat; Jul 3rd, 2009 at 4:09 pm.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 489
Reputation: shadwickman will become famous soon enough shadwickman will become famous soon enough 
Solved Threads: 76
shadwickman's Avatar
shadwickman shadwickman is offline Offline
Posting Pro in Training

Re: Python and the internet

 
0
  #5
Jul 3rd, 2009
Yep, no errors whatsoever with my Python 2.5.4 installation either...
"Two good old boys in a fire-apple red convertible. Stoned. Ripped. Twisted. Good people."
- Hunter S. Thompson

my photography
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,475
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 128
evstevemd's Avatar
evstevemd evstevemd is online now Online
Nearly a Posting Virtuoso

Re: Python and the internet

 
0
  #6
Jul 3rd, 2009
No errors to me too (Vega's version)
Check your python installation
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
---- Python, C++ PHP and Java ----
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,145
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 949
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Python and the internet

 
0
  #7
Jul 3rd, 2009
It could be the way 'Your_mum' is connected to the internet, maybe there is a filter or firewall somewhere. After all, 'www.Python.com' is a porn site.
Last edited by vegaseat; Jul 3rd, 2009 at 4:57 pm.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 312 | Replies: 6
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC