这是在 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)
被执行,程序进入到 except 部分。它不会崩溃,只是将“授权码错误,请重试”写入其他网页。
编辑:服务器打印到命令行的内容:
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)
将第一个客户端重命名为其他名称后,它起作用了。