Connecting to internet under proxy

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chema

    #1

    Connecting to internet under proxy

    Hi all.

    I have a little script to connect to the internet and download some
    files. I developed it in my house (direct connection) and it wordked
    properly. But the problem is that in the office (under a proxy) it
    doesn't run. My script is like:

    import urllib
    f=urllib.urlope n(SOME_WEB)
    print f.read

    I have tried to set the environmet variable
    http_proxy="192 .168.1.100:2929 " and also:

    import urllib
    proxy={'http',' http://192.168.1.100:2 929'} and using
    f=urllib.urlope n(SOME_WEB, proxy)
    print f.read

    the error was always the same:

    (11001, 'getaddrinfo failed')


    Any idea?? The proxy that we use is normally, in some programs I use a
    tipical http proxy without authentificatio n without problem.

    Thanks in advanced.

    Bye

  • Steve Holden

    #2
    Re: Connecting to internet under proxy

    Chema wrote:
    Hi all.
    >
    I have a little script to connect to the internet and download some
    files. I developed it in my house (direct connection) and it wordked
    properly. But the problem is that in the office (under a proxy) it
    doesn't run. My script is like:
    >
    import urllib
    f=urllib.urlope n(SOME_WEB)
    print f.read
    >
    I have tried to set the environmet variable
    http_proxy="192 .168.1.100:2929 " and also:
    >
    import urllib
    proxy={'http',' http://192.168.1.100:2 929'} and using
    f=urllib.urlope n(SOME_WEB, proxy)
    print f.read
    >
    the error was always the same:
    >
    (11001, 'getaddrinfo failed')
    >
    >
    Any idea?? The proxy that we use is normally, in some programs I use a
    tipical http proxy without authentificatio n without problem.
    >
    Thanks in advanced.
    >
    sholden@bigboy /c/colinux
    $ export http_proxy="htt p://localhost:37004 "

    sholden@bigboy /c/colinux
    $ python
    Python 2.5b2 (trunk:50713, Jul 19 2006, 16:04:09)
    [GCC 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)] on cygwin
    Type "help", "copyright" , "credits" or "license" for more information.
    Started with C:/Steve/.pythonrc
    >>import urllib
    >>u = urllib.urlopen( "http://www.holdenweb.c om/")
    >>>
    OK, it works with an environment variable (I saw the access in my
    mousehole proxy log). Now in a new shell:

    sholden@bigboy ~
    $ export | grep http

    sholden@bigboy ~
    $ python
    Python 2.5b2 (trunk:50713, Jul 19 2006, 16:04:09)
    [GCC 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)] on cygwin
    Type "help", "copyright" , "credits" or "license" for more information.
    Started with C:/Steve/.pythonrc
    >>import urllib
    >>proxy = {'http': 'http://localhost:37004 '}
    >>u = urllib.urlopen( "http://www.holdenweb.c om/", proxies=proxy)
    >>>
    Yup. that worked too. Maybe it's just because you aren't making proxies
    a keyword argument? If I try that (under cygwin) I see:
    >>u = urllib.urlopen( "http://www.holdenweb.c om/", proxy)
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/local/lib/python2.5/urllib.py", line 84, in urlopen
    return opener.open(url , data)
    File "/usr/local/lib/python2.5/urllib.py", line 192, in open
    return getattr(self, name)(url, data)
    File "/usr/local/lib/python2.5/urllib.py", line 327, in open_http
    h.send(data)
    File "/usr/local/lib/python2.5/httplib.py", line 707, in send
    self.sock.senda ll(str)
    File "<string>", line 1, in sendall
    TypeError: sendall() argument 1 must be string or read-only buffer, not dict

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://holdenweb.blogspot.com
    Recent Ramblings http://del.icio.us/steve.holden

    Comment

    • Schronos

      #3
      Re: Connecting to internet under proxy

      I don't know where is the problem, but I tried the same that you put
      and it failed.

      I tested it under cygwin, a cmd, linux with 2.2, 2.3 and 2.4 python
      version. I think taht the problem is my corporate proxy. In this
      sentences we use always a http proxy, but perhaps is not the suitable
      kind of proxy. :-( I don't know, it is only an idea, 'cause in my other
      programs I always use an http proxy and it work properly.

      thank's for all.

      Chema.

      Comment

      Working...