I’m having a very strange issue with AppEngine and the Context.IO API.
I’m using a the contextIO2 library, which uses python-oauth2.
When I try out the library (contextIO2) via the terminal, I get no problems (or at least, not yet. But I’ve tried it several dozen times across a couple of days without problem).
But when running code on AppEngine, I sometimes get a 401 Authorization Invalid consumer key error. I’m not sure what causes it, since one minute the request goes fine, then when I try the request again I get the 401, then after a while it will be fine, then not fine again, so on.
I emailed Context.IO support, and he said that when he tries the url of my app and got the error, “oauth_consumer_key doesn’t seem to be correctly transmitted”. What could be causing this? AppEngine messing up the request? pythoan-oauth2 bug? contextIO2 bug?
Here’s one of my handlers’ code:
class ReceiveConnectTokenHandler(webapp2.RequestHandler):
def get(self):
contextio_token = self.request.get('contextio_token')
cio = ContextIO(API_KEY, API_SECRET)
# get token's associated email
try:
token = cio.get_connect_token(contextio_token)
except RequestError, e:
if e.status_code == 404:
self.response.write(
'Token %s not found. ' % contextio_token)
return
raise e
account = token.account
if not account or not account.email_addresses:
self.response.write(
'Token %s has no email associated with it yet.' % contextio_token)
return
email = account.email_addresses[0]
# clear email's memcache
memcache.delete_multi(['accounts', 'no_account'], namespace=email)
self.response.write(
'''%s is now connected with Context.IO. Please verify in the
gadget that you have granted access. You can close this window.''' % email
)
It’s just a simple GET on https://api.context.io/2.0/connect_tokens/{{token}}
Posting answer as per Greg’s suggestion.
The issue was that the contextIO2 library defined it’s
request_urimethod by:which is a common Python pitfall (#5 in this list). I’ve notified Context.IO support and have sent a pull request.