Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do OAuth-requiring operations in a GAE Task Queue?
    primarykey
    data
    text
    <p>I have a simple Google App Engine app that includes a <code>/update</code> page which updates a YouTube playlist. It looks like this:</p> <pre><code>class UpdatePage(webapp2.RequestHandler): @decorator.oauth_required def get(self): update_result = self.update_playlist() ... routes = [('/update', UpdatePage), (decorator.callback_path, decorator.callback_handler())] app = webapp2.WSGIApplication(routes, debug=True) </code></pre> <p>It works as expected and the <code>update_playlist()</code> method does its job, but it turns out that under some circumstances it can run for a pretty long time, resulting in a <code>DeadlineExceededError</code>. So after reading about the available options, I figured the <em>Task Queue</em> API is the way to go (right?) and I'm trying to use it, following the <a href="https://developers.google.com/appengine/docs/python/taskqueue/overview-push#Using_Push_Queues_in_Python" rel="nofollow">Using Push Queues in Python</a> guide.</p> <p>&rarr; In short, I split <code>UpdatePage</code> into <code>UpdatePageHandler</code> + <code>UpdatePageWorker</code>:</p> <pre><code>class UpdateHandlerPage(webapp2.RequestHandler): @decorator.oauth_required def get(self): taskqueue.add(url='/updateworker') class UpdateWorkerPage(webapp2.RequestHandler): def post(self): update_result = self.update_playlist() ... routes = [('/update', UpdateHandlerPage), ('/updateworker', UpdateWorkerPage), (decorator.callback_path, decorator.callback_handler())] app = webapp2.WSGIApplication(routes, debug=True) </code></pre> <p>Unfortunately, after doing the split it seems my OAuth2 decorator no longer does its job:</p> <pre><code>INFO 2013-05-30 17:08:53,971 discovery.py:709] URL being requested: https://www.googleapis.com/youtube/v3/playlists?alt=json&amp;part=snippet%2Cstatus WARNING 2013-05-30 17:08:53,975 urlfetch_stub.py:480] Stripped prohibited headers from URLFetch request: ['content-length'] INFO 2013-05-30 17:08:54,351 client.py:493] Refreshing due to a 401 INFO 2013-05-30 17:08:54,361 appengine.py:276] make: Got type &lt;class 'google.appengine.api.datastore_types.Blob'&gt; INFO 2013-05-30 17:08:54,363 appengine.py:289] validate: Got type &lt;class 'oauth2client.client.OAuth2Credentials'&gt; INFO 2013-05-30 17:08:54,364 client.py:680] Refreshing access_token INFO 2013-05-30 17:08:54,746 client.py:699] Failed to retrieve access token: { "error" : "invalid_grant" } INFO 2013-05-30 17:08:54,757 appengine.py:276] make: Got type &lt;class 'google.appengine.api.datastore_types.Blob'&gt; INFO 2013-05-30 17:08:54,759 appengine.py:289] validate: Got type &lt;class 'oauth2client.client.OAuth2Credentials'&gt; INFO 2013-05-30 17:08:54,761 appengine.py:289] validate: Got type &lt;class 'oauth2client.client.OAuth2Credentials'&gt; INFO 2013-05-30 17:08:54,762 appengine.py:265] get: Got type &lt;class 'oauth2client.appengine.CredentialsModel'&gt; </code></pre> <p>And if instead of decorating <code>UpdateHandlerPage:get</code> I decorate <code>UpdateWorkerPage:post</code>, I get an infinite failure loop instead:</p> <pre><code>INFO 2013-05-30 17:24:31,307 discovery.py:190] URL being requested: https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest?userIp=127.0.0.1 INFO 2013-05-30 17:24:34,960 dev_appserver.py:3105] "GET /update HTTP/1.1" 200 - INFO 2013-05-30 17:24:35,060 dev_appserver.py:3105] "POST /updateworker HTTP/1.1" 302 - WARNING 2013-05-30 17:24:35,065 taskqueue_stub.py:1980] Task task1 failed to execute. This task will retry in 0.100 seconds INFO 2013-05-30 17:24:35,240 dev_appserver.py:3105] "POST /updateworker HTTP/1.1" 302 - WARNING 2013-05-30 17:24:35,245 taskqueue_stub.py:1980] Task task1 failed to execute. This task will retry in 0.200 seconds ... </code></pre> <p>What can I do? Thanks for your help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload