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

BadRequest from gcs APIs while downloading file cotent to file_obj #249

Closed
priyanshujain opened this issue Aug 18, 2020 · 5 comments
Closed
Assignees
Labels
api: storage Issues related to the googleapis/python-storage API. type: question Request for information or clarification. Not an issue.

Comments

@priyanshujain
Copy link

I am trying to download file content to a file using blob.download_to_file function but it's getting 400 from from GCS APIs while fetching the file content.

Environment details

  • MacOS Catalina 10.15
  • Python version: 3.8
  • pip version: 20.1.1
  • google-cloud-storage version: 1.3

Code example

def write_to_file(self, file_path, file_obj, encryption_key):
        """
        write file content to file obj.
        """
        # TODO: add error check for `file_obj`
        blob = self.get_blob(file_path, encryption_key=encryption_key)
        blob.download_to_file(file_obj)
        file_obj.seek(0)
        return file_obj

Stack trace

  File "/Users/PJ/Documents/Workspace/projects/white/box/lib/gcs/storage.py", line 68, in write_to_file
    blob.download_to_file(file_obj)
  File "/Users/PJ/.local/share/virtualenvs/white-Pt7g6jSz/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 1008, in download_to_file
    _raise_from_invalid_response(exc)
  File "/Users/PJ/.local/share/virtualenvs/white-Pt7g6jSz/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 3262, in _raise_from_invalid_response
    raise exceptions.from_http_status(response.status_code, message, response=response)
google.api_core.exceptions.BadRequest: 400 GET https://storage.googleapis.com/download/storage/v1/b/spotlight-stag/o/COVReport_Final_20200320-2020-07-29-165239-defd0fdbe121411b8a3a419f87c5594b.pdf?generation=1596041564648328&alt=media: ('Request failed with status code', 400, 'Expected one of', <HTTPStatus.OK: 200>, <HTTPStatus.PARTIAL_CONTENT: 206>)

Thanks!

@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/python-storage API. label Aug 18, 2020
@HemangChothani HemangChothani self-assigned this Aug 19, 2020
@priyanshujain
Copy link
Author

@HemangChothani I saw the discussion on #235, My main concern is the error from the GCS API, as I tried this error is only happening while I download content to file/file_obj/string, Should I also report this to storage API?

@priyanshujain
Copy link
Author

@HemangChothani I think this was happening because I was not providing encryption_key and this file was encrypted using the key. But it should show that encryption_key is not provided.

@HemangChothani
Copy link
Contributor

@priyanshujain If your concern is related to the error message, then wait for the PR to be merged and for the latest release of google-cloud-storage.

If problem is related to the download content to file/file_obj/string then ping me again.

@HemangChothani
Copy link
Contributor

@priyanshujain If your blob was encrypted by key when you have uploaded then when you are going to download it or retrieve it you need to pass encryption_key.
I have verified with that PR, it will give the actual reason of error, so no need to filed another issue.

If you are not passing the encryption_key then it will give error like The target object is encrypted by a customer-supplied encryption key.

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Aug 19, 2020
@HemangChothani HemangChothani added type: question Request for information or clarification. Not an issue. and removed triage me I really want to be triaged. labels Aug 19, 2020
@HemangChothani
Copy link
Contributor

@priyanshujain Closing this issue as resolved by PR #235

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/python-storage API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants