尝试使用其Python API连接到Dropbox,但失败了

时间:2013-08-13 03:37:52

标签: python google-app-engine dropbox

这是在Google App Engine中。我正在尝试在开始时加载Dropbox API请求授权页面,然后在单击“允许”按钮时重定向到我的OtherPage,最后将客户端用于其他目的。到目前为止,这是我的代码:

import webapp2
import cgi
import urllib2
from dropbox import client, rest, session

# app key and secret from Dropbox developer website
app_key = 'key'
app_secret = 'secret'
access_type = 'dropbox'

sess = session.DropboxSession(app_key, app_secret, access_type)
request_token = sess.obtain_request_token()

class MainPage(webapp2.RequestHandler):

    def get(self):
        url = sess.build_authorize_url(request_token, '')
        self.redirect(url)

class OtherPage(webapp2.RequestHandler):

    def get(self):
        try:
            self.response.write('<html><body>Testing:')
            access_token = sess.obtain_access_token(request_token)
            client = client.DropboxClient(sess)
            ...(other code)...
            self.response.write('</body></html>')
        except:
            self.response.write('<html><body>Incorrect authorization code, please try again.</body></html')

之后的try块中没有代码
access_token = sess.obtain_access_token(request_token)
执行

,程序进入除外部分。它不会崩溃,只需写入“不正确的授权码,请再试一次”到其他网页。

编辑:服务器打印到命令行的内容:

INFO     2013-08-13 03:43:50,755 sdk_update_checker.] Checking for updates to the SDK.
INFO     2013-08-13 03:43:51,233 sdk_update_checker.] The SDK is up to date.
INFO     2013-08-13 03:43:51,252 api_server.] Starting API server at: 
INFO     2013-08-13 03:43:51,270 dispatcher.] Starting module "default" running at: 
INFO     2013-08-13 03:43:51,273 admin_server.] Starting admin server at: 
INFO     2013-08-13 03:43:57,594 module.] default: "GET / HTTP/1.1" 302 -
INFO     2013-08-13 03:44:01,062 module.] default: "GET /other?uid=162326169&oauth_token=Qoxo0R0Ki3q5NzWM HTTP/1.1" 200 118
INFO     2013-08-13 03:44:01,224 module.] default: "GET /favicon.ico HTTP/1.1" 404 154

编辑2:解决了。删除try和exception块并运行try块中的内容后,线路出现问题

client = client.DropboxClient(sess)

将第一个客户端重命名为其他客户端后,它就可以了。

0 个答案:

没有答案