-
Notifications
You must be signed in to change notification settings - Fork 2.5k
BatchHTTPRequest: only add access token header if we have it #434
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
Conversation
Can you show me a case where this is problematic? |
d94cb5b
to
1919655
Compare
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 .
1919655
to
bdf5ea8
Compare
sure! my repro is pretty much the same as @mgilson's in his original report in #350: from apiclient import discovery
import httplib2
service = discovery.build('plus', 'v1')
batch = service.new_batch_http_request()
batch.add(service.comments().list(activityId='123'))
# creds is an instance of oauth2client.client.OAuth2Credentials
http = creds.authorize(httplib2.Http())
batch.execute(http=http) which results in:
with this PR, it runs fine. now, to get it to pass the tests... :P |
I don't know if it's helpful -- I haven't looked at this for quite a while, but way-way back I put together a branch/fork that seemed to work. You can see my changes: https://github.com/mgilson/google-api-python-client/compare/master...mgilson:app-default-creds?expand=1 Obviously don't trust that this actually works :-). |
@mgilson it does work! i actually ran that patch in production for months, until just yesterday, and based this PR on it. thank you! |
...to get the bug fix in googleapis/google-api-python-client#434
Can you get this merged to finally fix the |
I don't think this PR covers the case where |
Okay, getting to the source of this issue it's this:
Because of this behavior, when you have the following situation:
Then the I can remedy this by making |
I've decided I'm going to resolve this by making This does not in itself fix the example given. You will need to do one more thing to make this work as expected which is explicitly tell PR incoming, but let me know if anyone disagrees with this. |
thank you for working on this @jonparrott! that approach sgtm. i can easily add |
From my testing doing that alone fixes this in the |
…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)
re-fixes #350. it was originally fixed by c669a3b following discussion in #351 (comment) , but then that fix got lost in the next commit, 282fc88 .