socket in python with proxies

Jean-Paul Calderone exarkun at divmod.com
Fri Dec 21 07:40:42 EST 2007


On Fri, 21 Dec 2007 15:38:03 +1100, Astan Chee <stanc at al.com.au> wrote:
>Hi, I have a proxy server that requires authentication on a non-standard
>port and Im trying to connect to it via socket.connect()
>I tried doing this:
>import socket
>server = ("username:password at proxyaddrs.com",1234)
>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>s.connect(server)
>
>I keep getting the
>
>Traceback (most recent call last):
>  File "<pyshell#6>", line 1, in <module>
>    s.connect(server)
>  File "<string>", line 1, in connect
>gaierror: (11001, 'getaddrinfo failed')
>
>What does this mean? and can I actually use username/password to connect
>using a socket in python?

You can't specify credentials to a proxy this way.  The first element of
the address tuple for an AF_INET socket is a hostname or IP address.  If
you have a proxy which requires authentication, you must authenticate
after you have established the connection by sending bytes over the socket.

I don't know what kind of proxy you have, so I don't know what bytes you
have to send.

Jean-Paul



More information about the Python-list mailing list