This is in Google App Engine. I'm trying to load the Dropbox API Request Authorization page at the beginning, then redirect to my OtherPage when the "Allow" button is clicked, and finally use client for other purposes. Here's my code so far:
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')
None of the code in the try block after
access_token = sess.obtain_access_token(request_token)
is executed, and the program goes to the except part. It doesn't crash, just writes "Incorrect authorization code, please try again" to the Other web page.
Edit: What the server prints to command line:
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
Edit 2: Solved. After removing the try and exception blocks and just running what's in the try block, it took issue with the line
client = client.DropboxClient(sess)
After renaming the first client to something else, it worked.