Tuesday, April 24, 2012

Writing files to Dropbox account from GAE

I am trying to create files in a Dropbox.com folder from a GAE application.
I have done all the steps the register a Dropbox application and installed the Python SDK from Dropbox locally on my development machine. (see dropbox.com API).
It all works perfectly when I use the cli_client.py test script in the dropbox SDK on my local machine to access dropbox - can 'put' files etc.



I now want to start working in GAE environment, so things get a bit tricky.
Some help would be useful.



For those familiar with the Dropbox API code, I had the following issues thus far:



Issue 1



The rest.py Dropbox API module uses pkg_resources to get the certs installed in site-packages of a local machine installation.
I replaced



TRUSTED_CERT_FILE = pkg_resources.resource_filename(__name__, 'trusted-certs.crt')


with



TRUSTED_CERT_FILE = file('trusted-certs.crt')


and placed the cert file in my GAE application directory. Perhaps this is not quite right; see my authentication error code below.



Issue 2



The session.py Dropbox API module uses oauth module, so I changed the include to appengine oauth.



But raised an exception that GAE's oauth does not have OAuthConsumer method used by the Dropbox session.py module. So i downloaded oauth 1.0 and added to my application an now import this instead of GAE oauth.



Issue 3



GAE ssl module does not seem to have CERT_REQUIRED property.



This is a constant, so I changed



self.cert_reqs = ssl.CERT_REQUIRED


to



self.cert_reqs = 2


This is used when calling



ssl.wrap_socket(sock, cert_reqs=self.cert_reqs, ca_certs=self.ca_certs)


Authentication Error



But I still can't connect to Dropbox:



Status: 401
Reason: Unauthorized
Body: {"error": "Authentication failed"}
Headers: [('date', 'Sun, 19 Feb 2012 15:11:12 GMT'), ('transfer-encoding', 'chunked'), ('connection', 'keep-alive'), ('content-type', 'application/json'), ('server', 'dbws')]




No comments:

Post a Comment