Connecting to dropbox via python over a proxy
Question: i am trying to connect to a Dropbox Account with python 2.7.4 (x64 win7) and
their guide
[here](https://www.dropbox.com/developers/core/authentication#python) helped
me a lot. However when i am behind a proxy and this code just won't do it.
(From home the code works great, where i am not behind the proxy)

I tried to fiddle with the urllib2 and httplib which are used in the
**dropbox/rest.py** but had no luck. I know i have to change the Connection
Code but i am not sure how to do this for a Socket.

**dropbox/rest.py** [line:99]

    
    
    def create_connection(address):
        host, port = address
        err = None
        for 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 is not None:
                    sock.close()
    
        if err is not None:
            raise err
        else:
            raise socket.error("getaddrinfo returns an empty list")
    

i always get the error: [Errno 10060] SocketError. I don't really know a lot
about networks and ports but i know i can connect to the proxy on port 3128
and dropbox waits on 433. For that matter i had trouble connecting to any
**https://** -adress. So i found this code:

    
    
    proxyHost = 'www.myProxy.adress.com'
    proxyPort = 3128
    conn = httplib.HTTPConnection(proxyHost, proxyPort)
    conn.request("POST", "https://www.google.com")
    

Which works but i lack the skills to adapt this to the socket connection.
Especially confusing is that i give the proxyAdress to the connection and have
to write the Request in the header or somewhere, compared to the usually way,
where i can give the final-Adress to the connection.

This was when i read about [SOCKS](http://sourceforge.net/projects/pysocks/)
for python and tried them but i could not easily replace the socket code with
the new "_socksocket_ " for which a proxy can be 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 to change the create_connection func of the rest.py to work with
a proxy is highly appreciated.


Answer: I just ran into this issue myself and in searching for a solution came across
this post.

I've managed to resolve this with a minor modification to the dropbox/rest.py
code.

In the RESTClientObject class's **init** method change:

    
    
       self.pool_manager = urllib3.PoolManager(
            num_pools=4, # only a handful of hosts. api.dropbox.com, api-content.dropbox.com
            maxsize=max_reusable_connections,
            block=False,
            timeout=60.0, # long enough so datastores await doesn't get 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, # only a handful of hosts. api.dropbox.com, api-content.dropbox.com
            maxsize=max_reusable_connections,
            block=False,
            timeout=60.0, # long enough so datastores await doesn't get interrupted
            cert_reqs=ssl.CERT_REQUIRED,
            ca_certs=TRUSTED_CERT_FILE,
            ssl_version=ssl.PROTOCOL_TLSv1,
            proxy_url ='http://yourproxy.com:proxyport/',
        )
    

Note the change to use ProxyManager rather than PoolManager and the addition
of the proxy_url.

There are ways to authenticate against the proxy, but I haven't explored
those. So this will only work if you've already authenticated via Internet
Explorer or similar.

Hope this helps someone.

