0

I am learning how to use the Dropbox Python SDK. However, I run into a problem when I try to generate my request token. Here is the code I am using (note that I have replaced my actual app key and secret with APP_KEY and APP_SECRET here, but I used my actual app key and secret when I try it out.)

from dropbox import client, rest, session
APP_KEY = 'APP_KEY'
APP_SECRET = 'APP_SECRET'
ACCESS_TYPE = 'app_folder'
print 'Creating session object'
sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE)
print 'Session created!\nCreating request token'
request_token = sess.obtain_request_token()
print 'Created request token!'
url = sess.build_authorize_url(request_token)
print url
raw_input()
access_token = sess.obtain_access_token(request_token)
client1 = client.DropboxClient(sess)
print client1.account_info()

I had the program print out messages as it was creating the different objects so that I could see where the error occurred. This is the output:

aaron@Aarons-Ubuntu-Computer:~/Twisted$ python example.py
Creating session object
Session created!
Creating request token
Traceback (most recent call last):
  File "example.py", line 8, in <module>
    request_token = sess.obtain_request_token()
File "/usr/local/lib/python2.7/dist-packages/dropbox-1.4-py2.7.egg/dropbox/session.py", line 160, in obtain_request_token
response = rest.RESTClient.POST(url, headers=headers, params=params, raw_response=True)
File "/usr/local/lib/python2.7/dist-packages/dropbox-1.4-py2.7.egg/dropbox/rest.py", line 140, in POST
  return cls.request("POST", url, post_params=params, headers=headers, raw_response=raw_response)
File "/usr/local/lib/python2.7/dist-packages/dropbox-1.4-py2.7.egg/dropbox/rest.py", line 64, in request
  conn = ProperHTTPSConnection(host, 443)
File "/usr/local/lib/python2.7/dist-packages/dropbox-1.4-py2.7.egg/dropbox/rest.py", line 214, in __init__
  self.cert_reqs = ssl.CERT_REQUIRED
AttributeError: 'module' object has no attribute 'CERT_REQUIRED'

I had tried using this code before, and I didn't experience this problem. I have also removed the Dropbox SDK and reinstalled it, with no result. What is causing this problem, and how can I fix it?

UPDATE

After adding Kannan's code, the output looks like this: Ready Generating session Session Generated! Generating request token ['Certificate', 'CertificateOptions', 'CertificateRequest', 'Client', 'ClientContextFactory', 'Connector', 'ContextFactory', 'DN', 'DefaultOpenSSLContextFactory', 'DistinguishedName', 'KeyPair', 'Port', 'PrivateCertificate', 'SSL', 'Server', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'implementedBy', 'implements', 'implementsOnly', 'interfaces', 'supported', 'tcp'] Then I get the error. I have tried re-created my SSL certificates with no luck.

3
  • Did you also do print ssl.__file___? From the dir(ssl) results, it looks like you're getting Twisted's twisted.internet.ssl instead of the standard ssl. Maybe your import path is messed up? Commented Jun 28, 2012 at 15:13
  • You were right! ssl.__file__ prints out /usr/lib/python2.7/dist-packages/twisted/internet/ssl.pyc. I had forgotten that I imported *-twisted.internet.ssl, so that I could establish a secure connection between my client and server programs. I tried changing the import statement to from twisted.internet import ssl a twisted_ssl so that it wouldn't interfere with Dropbox, and updated the reference to ssl in reactor.listenSSL. I am still having the ssl.CERT_REQUIRED error, though. Commented Jun 28, 2012 at 16:28
  • The Dropbox SDK does import ssl, so I don't know why the twisted.internet.ssl is getting imported. Check your PYTHONPATH environment variable to make sure it isn't set to include more than it should. Commented Jun 28, 2012 at 16:33

2 Answers 2

3

I'm getting the same error. I tried what you suggested, and it turns out that ssl module has no attribute 'file', and only has ['doc', 'loader', 'name', 'package'] when I print dir(ssl). Also worth noting is that when I try print str(ssl) in google app engine, I see: module 'ssl' (built-in) but when I run python from the command line, I see: module 'ssl' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.pyc' and the ssl from the command line has a file attribute.

Not sure how ssl is getting hijacked... but I'm pretty sure it is.

EDIT: loader is google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object at 0x1142684d0

EDIT: found a related problem here: SSLError on Google App Engine (local dev-server)

Sign up to request clarification or add additional context in comments.

Comments

1

This is strange. The Python 2.7 docs definitely mention ssl.CERT_REQUIRED.

Try modifying the SDK and, right before the line that fails, add in

print dir(ssl)
print ssl.__file__

That might help you figure out what's going wrong.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.