https - Connecting to dropbox via python over a proxy -
i trying connect dropbox account python 2.7.4 (x64 win7) , guide here helped me lot. when behind proxy , code won't it. (from home code works great, not behind proxy)
i tried fiddle urllib2 , httplib used in dropbox/rest.py had no luck. know have change connection code not sure how socket.
dropbox/rest.py [line:99]
def create_connection(address): host, port = address err = none res in socket.getaddrinfo(host, port, 0, socket.sock_stream): af, socktype, proto, canonname, sa = res sock = none try: sock = socket.socket(af, socktype, proto) sock.connect(sa) return sock except socket.error, _: err = _ if sock not none: sock.close() if err not none: raise err else: raise socket.error("getaddrinfo returns empty list")
i error: [errno 10060] socketerror. don't know lot networks , ports know can connect proxy on port 3128 , dropbox waits on 433. matter had trouble connecting https://-adress. found code:
proxyhost = 'www.myproxy.adress.com' proxyport = 3128 conn = httplib.httpconnection(proxyhost, proxyport) conn.request("post", "https://www.google.com")
which works lack skills adapt socket connection. confusing give proxyadress connection , have write request in header or somewhere, compared way, can give final-adress connection.
this when read socks python , tried them not replace socket code new "socksocket" proxy can set with:
import socks socks.setdefaultproxy(socks.proxy_type_socks5,"www.myproxy.adress.com") socket.socket = socks.socksocket urllib.urlopen("https://www.google.com/")
any help, how change create_connection func of rest.py work proxy highly appreciated.
i ran issue myself , in searching solution came across post.
i've managed resolve minor modification dropbox/rest.py code.
in restclientobject class's init method change:
self.pool_manager = urllib3.poolmanager( num_pools=4, # handful of hosts. api.dropbox.com, api-content.dropbox.com maxsize=max_reusable_connections, block=false, timeout=60.0, # long enough datastores await doesn't interrupted cert_reqs=ssl.cert_required, ca_certs=trusted_cert_file, ssl_version=ssl.protocol_tlsv1, )
to:
self.pool_manager = urllib3.proxymanager( num_pools=4, # handful of hosts. api.dropbox.com, api-content.dropbox.com maxsize=max_reusable_connections, block=false, timeout=60.0, # long enough datastores await doesn't interrupted cert_reqs=ssl.cert_required, ca_certs=trusted_cert_file, ssl_version=ssl.protocol_tlsv1, proxy_url ='http://yourproxy.com:proxyport/', )
note change use proxymanager rather poolmanager , addition of proxy_url.
there ways authenticate against proxy, haven't explored those. work if you've authenticated via internet explorer or similar.
hope helps someone.
Comments
Post a Comment