467,146 Members | 1,256 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,146 developers. It's quick & easy.

urllib.urlopen

Hello,
I'm trying to use the urllib module, but when i try urllib.urlopen, it
gives me a socket error:
import urllib
print urllib.urlopen('http://www.google.com/').read()

Traceback (most recent call last):
File "<input>", line 1, in ?
File "C:\Python24\lib\urllib.py", line 77, in urlopen
return opener.open(url)
File "C:\Python24\lib\urllib.py", line 180, in open
return getattr(self, name)(url)
File "C:\Python24\lib\urllib.py", line 296, in open_http
h.endheaders()
File "C:\Python24\lib\httplib.py", line 794, in endheaders
self._send_output()
File "C:\Python24\lib\httplib.py", line 675, in _send_output
self.send(msg)
File "C:\Python24\lib\httplib.py", line 642, in send
self.connect()
File "C:\Python24\lib\httplib.py", line 610, in connect
socket.SOCK_STREAM):
IOError: [Errno socket error] (11001, 'getaddrinfo failed')

Any ideas on what i did wrong?

Dec 17 '05 #1
  • viewed: 14050
Share:
6 Replies
JabaPyth wrote:
Hello,
I'm trying to use the urllib module, but when i try urllib.urlopen, it
gives me a socket error:
>>import urllib
>>print urllib.urlopen('http://www.google.com/').read()

Traceback (most recent call last):
File "<input>", line 1, in ?
File "C:\Python24\lib\urllib.py", line 77, in urlopen
return opener.open(url)
File "C:\Python24\lib\urllib.py", line 180, in open
return getattr(self, name)(url)
File "C:\Python24\lib\urllib.py", line 296, in open_http
h.endheaders()
File "C:\Python24\lib\httplib.py", line 794, in endheaders
self._send_output()
File "C:\Python24\lib\httplib.py", line 675, in _send_output
self.send(msg)
File "C:\Python24\lib\httplib.py", line 642, in send
self.connect()
File "C:\Python24\lib\httplib.py", line 610, in connect
socket.SOCK_STREAM):
IOError: [Errno socket error] (11001, 'getaddrinfo failed')

Any ideas on what i did wrong?

Works for me, do you have a proxy or some strange setup for accessing to
the web?

Try using the urllib2 module, too.
Dec 17 '05 #2
I tried using urllib2 and this is what i got:
import urllib2
the_url = 'http://www.google.com'
req = urllib2.Request(the_url)
handle = urllib2.urlopen(req)

Traceback (most recent call last):
File "<input>", line 1, in ?
File "C:\Python24\lib\urllib2.py", line 130, in urlopen
return _opener.open(url, data)
File "C:\Python24\lib\urllib2.py", line 358, in open
response = self._open(req, data)
File "C:\Python24\lib\urllib2.py", line 376, in _open
'_open', req)
File "C:\Python24\lib\urllib2.py", line 337, in _call_chain
result = func(*args)
File "C:\Python24\lib\urllib2.py", line 1021, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python24\lib\urllib2.py", line 996, in do_open
raise URLError(err)
URLError: <urlopen error (11001, 'getaddrinfo failed')>

Dec 18 '05 #3
Jay
Easy Fix...

import urllib
the_url = "http://www.google.com"
req = urllib.urlopen(the_url)

Does this work for you??

Dec 18 '05 #4

Jay wrote:
Easy Fix...

import urllib
the_url = "http://www.google.com"
req = urllib.urlopen(the_url)

Does this work for you??


This does look like proxie /firewall issue, try it from an internet
cafe. Also depending on the site, you may have to set User-Agnet
and/or referer headers. And definitely respect robots.txt, throttle
back requests to seom finite (human-scale) volume and save them to your
hard drive (mistakes i've made)

Dec 18 '05 #5
Thanks, guys.
I tried on a different computer, and it worked fine.I then found out
that my computer thyought i had a proxy server, and after i cleaned
that up, it worked.
Thanks again

Dec 18 '05 #6
On Sat, 17 Dec 2005, Dennis Lee Bieber wrote:
(Now there is an interesting technical term:
#define ERROR_ARENA_TRASHED 7)


FreeBSD at one point had an EDOOFUS; Apple kvetched about this being
offensive, so it was changed to EDONTPANIC.

I shitteth thee not.

tom

--
information distribution, vox humana, deviation, handle, feed, l.g. **
Dec 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Richard Shea | last post: by
11 posts views Thread by Pater Maximus | last post: by
reply views Thread by Pieter Edelman | last post: by
1 post views Thread by Timothy Wu | last post: by
4 posts views Thread by william@opensource4you.com | last post: by
reply views Thread by Ali.Sabil@gmail.com | last post: by
4 posts views Thread by kgrafals@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.