-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError
when trying to issue BatchHttpRequest
when service was built using application default credentials
#350
Comments
@mgilson thanks for this really detailed bug report. Are you willing to send a PR to fix this issue? If so, I'll be happy to review. |
This should address googleapis#350.
Sure, I can submit a PR. I've got a patch ready here, but I don't know anything about your test setup. I tried downloading
Have you ever seen anything like this before? |
This should address googleapis#350.
This should address googleapis#350.
This should address googleapis#350.
this bit me recently when i upgraded to oauth2client 4.1.1 and google-api-python-client 1.6.2. patching #351 into my local lib fixes it. i'd love to see that PR merged so it gets into the next release! |
Resolved by #376. |
re-fixes googleapis#350. it was originally fixed by c669a3b following discussion in googleapis#351 (comment) , but then that fix got lost in the next commit, googleapis@282fc88 .
re-fixes googleapis#350. it was originally fixed by c669a3b following discussion in googleapis#351 (comment) , but then that fix got lost in the next commit, googleapis@282fc88 .
re-fixes googleapis#350. it was originally fixed by c669a3b following discussion in googleapis#351 (comment) , but then that fix got lost in the next commit, googleapis@282fc88 .
…es_token as invalid. Closes #350, Supersedes #434 Note: This change reveals surprising behavior between default credentials and batches. If you allow `googleapiclient.discovery.build` to use default credentials *and* specify different credentials by providing `batch.execut()` with an explicit `http` argument, your individual requests will use the default credentials and *not* the credentials specified to the bathc http. To avoid this, tell `build` explicitly not to use default credentials by specifying `build(..., http=httplib2.Http()`. For context, see: #434 (comment)
this is a new workaround for googleapis/google-api-python-client#350, discussed in googleapis/google-api-python-client#434 (comment)
…es_token as invalid. (#469) Closes #350, Supersedes #434 Note: This change reveals surprising behavior between default credentials and batches. If you allow `googleapiclient.discovery.build` to use default credentials *and* specify different credentials by providing `batch.execut()` with an explicit `http` argument, your individual requests will use the default credentials and *not* the credentials specified to the bathc http. To avoid this, tell `build` explicitly not to use default credentials by specifying `build(..., http=httplib2.Http()`. For context, see: #434 (comment)
This issue is very similar to #211. My team has an app-engine application that uses batch requests in the Gmail API. After an upgrade of this client library, we started seeing failures:
Our usage of this client library looks like the following:
The
gmail_service
is cached at the application level to avoid needing to do an API call for each request (which is why it ends up with the application credentials). What I believe is happening is thatends up creating an
HttpRequest
that uses the samehttp
that was used to constructgmail_service
(i.e. the application credentials) and I believe that the application credentials have noaccess_token
. This results in theTypeError
seen above. The fix in #232 won't help (thehttp
that is getting passed tobatch_request.execute
is valid).It seems to me that the application of credentials in _serialize_request should be conditional on the credentials actually having an access token:
Otherwise, if the sub-request isn't authenticated then the authentication from the outer request should be used (at least, if the gmail docs are any indicator):
In the event that this behavior is actually working as intended or if my proposed fix isn't satisfactory and a real fix would be too difficult, a work-around to this issue is possible by updating the requests that you add to the batch with an appropriately authorized http instance. i.e changing the above to:
Seems to fix the issue.
The text was updated successfully, but these errors were encountered: