eshad / httplib2

Automatically exported from code.google.com/p/httplib2
0 stars 0 forks source link

Incorrect working with Proxy #76

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello, i have tried to use httplib2 with standard exmaple
[CODE]
import httplib2

httplib2.debuglevel=4
#3 - it is a constant in socksipy, which is means HTTP proxy
proxy_info = httplib2.ProxyInfo(3, '10.10.31.103', 3128, proxy_rdns=True)
h = httplib2.Http(proxy_info=proxy_info)
r,c = h.request("http://yandex.ru")
print r
print "#"*90
print c.decode("UTF-8")
[/CODE]

And there was a trouble, i got an error message ServerNotFoundError.
Trouble in that, that httplib ignoring rdns flag in ProxyInfo instance.
Actually, class HTTPConnectionWithTimeout is trying to get IP adrdress 
(sending DNS request) in LAN, our problem is that LAN DNS servers don`t 
know IP addresses of servers in WAN =/
I loocked at class HTTPSConnectionWithTimeout and saw that its really 
different from HTTPConnectionWithTimeout(more easier). Then  I saw that 
HTTPSConnectionWithTimeout is don`t do that really bad thing =/.
I have tried to get page, which is over SSL, and i saw that its working 
pretty good.
So, I have changed method connect of class HTTPConnectionWithTimeout
to 
[CODE]
    """Connect to the host and port specified in __init__."""
        if self.proxy_info and self.proxy_info.isgood():
            sock = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
            sock.setproxy(*self.proxy_info.astuple())
        else:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        if has_timeout(self.timeout):
            sock.settimeout(self.timeout)
        sock.connect((self.host, self.port))
        self.sock =sock
[/CODE]
And it`s start working.
Our proxy is Squid.
If this is not hard, please, make this patch in httplib2 (if it is nit 
change any other parts).

Original issue reported on code.google.com by login...@null.net on 30 Oct 2009 at 9:02

GoogleCodeExporter commented 9 years ago
Sorry for bad English. :(

Original comment by login...@null.net on 30 Oct 2009 at 9:03

GoogleCodeExporter commented 9 years ago
Sorry, actually it must be so (tested at home)
[CODE]
    "Connect to the host and port specified in __init__."
        if self.proxy_info and self.proxy_info.isgood():
            self.sock = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
            self.sock.setproxy(*self.proxy_info.astuple())
        else:
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        if has_timeout(self.timeout):
            self.sock.settimeout(self.timeout)
        self.sock.connect((self.host, self.port))
[/CODE]
Works fine for me

Original comment by login...@null.net on 7 Nov 2009 at 6:23

GoogleCodeExporter commented 9 years ago

Original comment by joe.gregorio@gmail.com on 13 Jun 2011 at 4:58