Skip to content
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

Using a signed Resumable Upload URL fails with 403 unless content_type is empty #289

Closed
williambrode opened this issue Dec 8, 2021 · 3 comments · Fixed by #290
Closed
Assignees
Labels
api: storage Issues related to the googleapis/google-resumable-media-python API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@williambrode
Copy link
Contributor

williambrode commented Dec 8, 2021

Environment details

  • Programming language: Python
  • OS: Ubuntu 20.04 in WSL2
  • Language runtime version: 3.8
  • Package version: cee4164

Steps to reproduce

  1. Generate a signed resumable upload url:
gsutil signurl -m RESUMABLE -c application/octet-stream -d 24h <key_file> gs://<bucket>/<obj>
  1. Run this python program, passing in the upload_url that was generated:
import io

from google.resumable_media import InvalidResponse
from google.resumable_media.requests import ResumableUpload
from requests import Session

chunk_size = 16 * 1024 * 1024  # 16MB

upload = ResumableUpload(upload_url, chunk_size)
stream = io.BytesIO(data)
metadata = {}
transport = Session()
transport.headers.update({'x-goog-resumable': 'start'})
try:
	response = upload.initiate(
		transport, stream, metadata, 'application/octet-stream')
except InvalidResponse as err:
	print(err.response.content)
	raise
print(response)
while not upload.finished:
	upload.transmit_next_chunk(transport)
stream.close()

You will get a 403 error from google that says The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.. This is because the content_type passed by the library to the signed url is not correct. If you instead generate the url without a content_type - it will succeed - but the object will have the content type application/json. I'll send in a PR shortly with a fix that works for me.

@williambrode williambrode added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 8, 2021
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/google-resumable-media-python API. label Dec 8, 2021
williambrode added a commit to williambrode/google-resumable-media-python that referenced this issue Dec 8, 2021
williambrode added a commit to williambrode/google-resumable-media-python that referenced this issue Dec 9, 2021
williambrode added a commit to williambrode/google-resumable-media-python that referenced this issue Dec 9, 2021
@cojenco cojenco self-assigned this Dec 15, 2021
@williambrode
Copy link
Contributor Author

@tseaver Any chance we could cut a release so I can switch back to the community version? Trying to do commit shas with pip is giving us headaches!

@tseaver
Copy link
Contributor

tseaver commented Feb 5, 2022

@williambrode I'm not a maintainer here any longer. @andrewsg or @cojenco could likely push out a release, though.

@cojenco
Copy link
Contributor

cojenco commented Feb 7, 2022

@williambrode We just cut a new release v2.2.0 this morning. Thanks for your patience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/google-resumable-media-python API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants