atuljain / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
0 stars 0 forks source link

Batch Execute raising errors when user revokes credentials #319

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Basically the execute method in BatchHttpRequest was throwing an exception when 
a single user's credentials were revoked and there was no way to identify which 
user had bad credentials because it never got to the callback function.

Please see my stack overflow post for further details: 
http://stackoverflow.com/questions/21150275/batch-request-to-multiple-users-fail
s-if-one-user-revokes-access

I tracked this down and fixed for myself with this patch.  I'm not sure if this 
is the best way to do it, but 

--- /google-api-python-client-1ab344e0a34d/apiclient/http.py
+++ /google-api-python-client-patched/apiclient/http.py
@@ -50,7 +50,7 @@
 from model import JsonModel
 from oauth2client import util
 from oauth2client.anyjson import simplejson
-
+from oauth2client.client import AccessTokenRefreshError

 DEFAULT_CHUNK_SIZE = 512*1024

@@ -1299,10 +1299,13 @@
     for request_id in self._order:
       resp, content = self._responses[request_id]
       if resp['status'] == '401':
-        redo_order.append(request_id)
-        request = self._requests[request_id]
-        self._refresh_and_apply_credentials(request, http)
-        redo_requests[request_id] = request
+        try:
+          request = self._requests[request_id]
+          self._refresh_and_apply_credentials(request, http)
+          redo_order.append(request_id)
+          redo_requests[request_id] = request
+        except AccessTokenRefreshError:
+          pass

     if redo_requests:
       self._execute(http, redo_order, redo_requests)

Original issue reported on code.google.com by bl...@oybro.com on 16 Jan 2014 at 1:16