我正在学习如何使用 Dropbox Python SDK。但是,当我尝试生成请求令牌时遇到了问题。这是我正在使用的代码(请注意,我在这里用 APP_KEY 和 APP_SECRET 替换了我的实际应用程序密钥和秘密,但我在尝试时使用了我的实际应用程序密钥和秘密。)
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()
我让程序在创建不同的对象时打印出消息,以便我可以看到错误发生的位置。这是输出:
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'
我之前曾尝试使用此代码,但没有遇到此问题。我还删除了 Dropbox SDK 并重新安装它,但没有任何结果。是什么导致了这个问题,我该如何解决?
更新
添加 Kannan 的代码后,输出如下所示:
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']
然后我得到错误。我试过重新创建我的 SSL 证书,但没有成功。