GeezerVison is showing github.com — File upload to Storage fails silently · Issue #1712 · googleapis/google-cloud-python
File upload to Storage fails silently #1712Labels api: storageIssues related to the Cloud Storage API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. DescriptionHello, I'm trying to upload a file to Storage from a Compute instance.
Following the example in the docs:
from gcloud import storage
client = storage.Client()
bucket = client.get_bucket('my-bucket-name')
blob = bucket.blob('my-test-file.txt')
blob.upload_from_string('this is test content!')
Nothing happens. No error message, no file created/uploaded in the bucket, blob.exists() returns False.
I don't think it's an access control/permissions thing as the bucket has default settings and I'm able to modify existing blobs.
Any leads on how to debug this?
Also, I think it would make sense to throw an exception or give some sort of indication/explanation that it failed. Reacted by orkenstein, Paul Fitzgerald, Catherine19950122 and Miguel Carvalho Activitydhermes commented on Apr 11, 2016 It should fail with an exception if the upload failed. The blob.exists() being False may be due to eventual consistency. tseaver commented on Apr 11, 2016 Thanks for the report! I'm guessing that bucket.exists() returns False: if so, then you need to call bucket.create() before blob.upload_from_string(). I was able to reproduce your report that way: the error is that the 404 from the back-end (due to the non-existent bucket) is being dropped on the floor. tseaver commented on Apr 11, 2016 > /home/tseaver/projects/agendaless/Google/src/gcloud-python/gcloud/streaming/http_wrapper.py(355)_make_api_request_no_retry()
-> if info is None:
(Pdb) pp info
{'alt-svc': 'quic=":443"; ma=2592000; v="32,31,30,29,28,27,26,25"',
'alternate-protocol': '443:quic',
'content-length': '165',
'content-type': 'application/json; charset=UTF-8',
'date': 'Mon, 11 Apr 2016 18:55:56 GMT',
'server': 'UploadServer',
'status': '404',
'vary': 'Origin, X-Origin',
'x-guploader-uploadid': 'AEnB2UqUUnsXbGr_B5UC4iut3KXc-TKQUbER1ffezwzKXKatM5ZRBetpJfJM90_-9p7yVZNK747V9Nm0ypPTIdy9U83mh8BUfg'}
(Pdb) pp content
'{\n "error": {\n "errors": [\n {\n "domain": "global",\n "reason": "notFound",\n "message": "Not Found"\n }\n ],\n "code": 404,\n "message": "Not Found"\n }\n}\n'liorsbg commented on Apr 11, 2016 Thanks for the quick reply!
@dhermes file doesn't show up ever, checked on the web viewer as well.
@tseaver bucket.exists() returns True.
On an existing file in the same bucket, everything works as expected (make_public, delete, etc...) tseaver commented on Apr 11, 2016 We do have a bug that the upload code drops 40x errors (other than 429 "Too Many Requests") on the floor. dhermes commented on Apr 11, 2016 tseaver commented on Apr 11, 2016 dhermes commented on Apr 11, 2016 tseaver commented on Apr 11, 2016 craigcitro commented on Apr 11, 2016 @thobrla for the error question -- Travis, do you remember this offhand? (If not, I'll take a look soon.) thobrla commented on Apr 11, 2016 I think the default CheckResponse function in http_wrapper only intends to process retryable errors. Non-retryable errors like 400, 403, 404, etc. are returned to the client who can interpret them depending on the application logic. dhermes commented on Apr 11, 2016 tseaver commented on Apr 11, 2016 Just guessing: is there a notion that a 404 is a "retriable" error in a general case? I can see how it would be for some cases (e.g., DELETE on a resource 404s due to eventual consistency), but that can't be a good overall rule. In general, 40x errors are "user errors", and should just be raised.
- 400 Bad Request (raise)
- 401 Unauthorized (raise)
- 403 Forbidden (raise)
- 404 Not Found (raise unless app policy says retry after backoff)
- 405 Method Not Allowed (raise)
- 406 Not Acceptable (raise)
- 408 Request Timeout (retriable after backoff?)
- 409 Conflict (maybe retriable after backoff?)
- 410 Gone (raise)
- 411 Length Required (raise)
- 412 Precondition Failed (raise)
- 413 Request Entity Too Large (raise)
- 414 Request-URI Too Long (raise)
- 415 Unsupported Media Type (raise)
- 416 Requested Range Not Satisfiable (raise unless app policy says retry after backoff)
- 417 Expectation Failed (raise)
The 50x "Server Error" codes are also a mixed bag:
- 500 Internal Server Error (maybe retriable after backoff?)
- 501 Not Implemented (raise)
- 502 Bad Gateway (retriable after backoff)
- 503 Service Unavailable (retriable after backoff)
- 504 Gateway Timeout (retriable after backoff)
- 505 HTTP Version Not Supported (raise)
craigcitro commented on Apr 11, 2016 thobrla commented on Apr 11, 2016 Outside of 429, all of the 400's would only be retriable in very application-specific scenarios. So I think sending the response to the client is appropriate.
500 is retriable after backoff.
I agree that 501/505 are unlikely to succeed with retries. Right we aren't bitten by that because the services simply don't return those error codes (and we're using supported HTTP versions). tseaver commented on Apr 11, 2016 @craigcitro nope: somehow the knowledge of that didn't transfer, and so we were dropping the errors on the floor. #1717 adds code to the caller of our (forked) apitools to handle error responses. dhermes commented on Apr 18, 2016 @tseaver Have you been able to verify that this fixes the issue here? I tried it and can't get the original snippet to fail (get_bucket() would fail if the bucket didn't exist, and the upload would never occur). tseaver commented on Apr 18, 2016 @dhermes I was never able to reproduce with an already-existing bucket. I did verify that the code now raises a NotFound:
>>> from gcloud.storage import Client
>>> client = Client()
>>> bucket = client.bucket('1712-tseaver-no-such-bucket')
>>> bucket.exists()
False
>>> blob = bucket.blob('my-blob-name')
>>> blob.upload_from_string('this is test content!')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "gcloud/storage/blob.py", line 548, in upload_from_string
client=client)
File "gcloud/storage/blob.py", line 469, in upload_from_file
self._check_response_error(request, http_response)
File "gcloud/storage/blob.py", line 359, in _check_response_error
error_info=request.url)
gcloud.exceptions.NotFound: 404 Not Found (https://www.googleapis.com/upload/storage/v1/b/1712-tseaver-no-such-bucket/o?uploadType=media&name=my-blob-name)dhermes commented on Apr 18, 2016 I confirmed as well. Thanks for the snippet.
MetadataMetadataapi: storageIssues related to the Cloud Storage API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. DevelopmentNo branches or pull requestsIssue actions
|