Search code examples
pythongoogle-app-engineoauthflickr

Flickr OAuth from Google App Engine Python


I have a weird problem with Flickr OAuth on Google App Engine:

I'm requesting for oauth token and secret from Flickr using the code attached.. it fails most of time when tested on App Engine.. Flickr returns a page saying

"Flickr has the hiccups. We're looking into the problem right now..."

At first I thought it might be the problem with Flickr.. but then if I copied the URL into chrome directly, I could get the oauth token and secret.. So I thought it could be the problem with my code fetching the URL.. but in fact, with the same piece of code, I'm also able to get token and secret at localhost..

Now I'm really confused.. because this used to work perfectly until recently.. is there any update on App Engine dev server that might cause the problem? Please help!!!

        url = "http://www.flickr.com/services/oauth/request_token"
        params = {
            "oauth_timestamp": str(int(time())),
            "oauth_signature_method": "HMAC-SHA1",
            "oauth_version": "1.0",
            "oauth_nonce": sha1(str(random())).hexdigest(),
            "oauth_callback": API_CALLBACK,
            "oauth_consumer_key": API_KEY,
        }
        # Setup the Consumer with the key-secret given by Flickr
        consumer = oauth2.Consumer(key=API_KEY, secret=API_SECRET)

        # Create request
        req = oauth2.Request(method="GET", url=url, parameters=params)

        # Create signature
        signature = oauth2.SignatureMethod_HMAC_SHA1().sign(req, consumer, None)

        # Add the Signature to the request
        req['oauth_signature'] = signature

        h = httplib2.Http()
        resp, content = h.request(req.to_url(), "GET")

Update: I changed the code a little bit, keep requesting if I don't get the token (given a max try allowed). It works... still, it is very annoying that I have to write such work-around. Would appreciate if better alternative is available!


Solution

  • You need to use https instead of http (see the comment thread above)