urllib.urlopen

Discussion in 'Python' started by JabaPyth, Dec 17, 2005.

  1. JabaPyth

    JabaPyth Guest

    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?
    JabaPyth, Dec 17, 2005
    #1
    1. Advertising

  2. JabaPyth

    Xavier Morel Guest

    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.
    Xavier Morel, Dec 17, 2005
    #2
    1. Advertising

  3. On 17 Dec 2005 13:38:53 -0800, "JabaPyth" <> declaimed
    the following in comp.lang.python:

    > Hello,
    > I'm trying to use the urllib module, but when i try urllib.urlopen, it
    > gives me a socket error:
    >

    Your firewall might be blocking outgoing Python connections. (I get
    error 7 if I set ZoneAlarm to block outgoing Python)

    File "E:\Plone_2\Python\lib\httplib.py", line 535, in connect
    socket.SOCK_STREAM):
    IOError: [Errno socket error] (7, 'getaddrinfo failed')

    Strange, the only errno 7 in my errno.h is E2BIG (and says "argument
    list is too large)

    11001 is WinSock for Host Not Found

    (Now there is an interesting technical term:
    #define ERROR_ARENA_TRASHED 7)
    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.netcom.com/> <
    Dennis Lee Bieber, Dec 17, 2005
    #3
  4. JabaPyth

    JabaPyth Guest

    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')>
    JabaPyth, Dec 18, 2005
    #4
  5. JabaPyth

    Jay Guest

    Easy Fix...

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

    Does this work for you??
    Jay, Dec 18, 2005
    #5
  6. JabaPyth

    gene tani Guest

    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)
    gene tani, Dec 18, 2005
    #6
  7. JabaPyth

    JabaPyth Guest

    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
    JabaPyth, Dec 18, 2005
    #7
  8. JabaPyth

    Tom Anderson Guest

    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. **
    Tom Anderson, Dec 19, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xu, C.S.
    Replies:
    5
    Views:
    462
    John J. Lee
    Sep 17, 2003
  2. Chris Withers

    urllib.urlopen with threads

    Chris Withers, Oct 9, 2003, in forum: Python
    Replies:
    0
    Views:
    307
    Chris Withers
    Oct 9, 2003
  3. Chris Withers

    Re: urllib.urlopen with threads

    Chris Withers, Oct 9, 2003, in forum: Python
    Replies:
    0
    Views:
    392
    Chris Withers
    Oct 9, 2003
  4. Replies:
    3
    Views:
    1,987
    Cousin Stanley
    Dec 31, 2003
  5. Chris
    Replies:
    0
    Views:
    1,033
    Chris
    Jul 10, 2005
Loading...

Share This Page