-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Storage: error on HTTP 206 Partial Content discards message leading to confusing errors #4222
Comments
A 206 just means it was a partial response (i.e. if you are downloading in chunks). This isreally tough to debug / code for without being able to reproduce. If you at least see it again, the stacktrace in Python 3 would be more useful (due to In [1]: def f():
...: raise ValueError
...:
In [2]: def g():
...: try:
...: f()
...: except:
...: raise RuntimeError
...:
In [3]: g()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-2-b4762a3d7a10> in g()
2 try:
----> 3 f()
4 except:
<ipython-input-1-1e378d1a95b8> in f()
1 def f():
----> 2 raise ValueError
ValueError:
During handling of the above exception, another exception occurred:
RuntimeError Traceback (most recent call last)
<ipython-input-3-5fd69ddb5074> in <module>()
----> 1 g()
<ipython-input-2-b4762a3d7a10> in g()
3 f()
4 except:
----> 5 raise RuntimeError
RuntimeError:
In [4]: Do you have a requirement to use 2.7? It seems we should be doing at least two things here:
|
Python 2.7: We have a large legacy App Engine Standard code base unfortunately. This particular thing does not run on App Engine, but it interacts with libraries that were written for 2.7, so unfortunately we need to use it. However: Yes, I think using As you might expect: I've basically seen this once, but this mystery did kill a couple hours today, since I was trying to make sure we didn't have a thread-safety issue (due to the weirdness of throwing an exception for a success HTTP status code), and because the binary data in the exception caused a unicode handling error. This code is downloading in chunks because I set the chunk size to 32 MiB at some point, maybe due to #2222. (Now that I look at this, I know the storage library has changed and its probably hurting us to do this, since it will now do it in a single request if I don't specify the chunk size ...) The log for this error contained the follow extra information:
This particular object is 268412 bytes, so I suspect length wasn't the problem. Unfortunately, due to the way the exception is handled, I have no way to tell what actually caused it :( |
If |
When raised by 'google.resumable_media' for responses without an error payload, the message and args are the only clue to the cause. Closes #4222.
In
download_to_file
, if the download code raisesresumable_media.InvalidResponse
[1], it calls_raise_from_invalid_response
, which callsexceptions.from_http_response
, which creates a new exception using the HTTP response inside theresumable_media.InvalidResponse
, which discards any exception message that was put there. This leads to confusing exceptions like the following (full stack trace below):This shows a 206 SUCCESS code, but apparently it still failed for some reason. Digging through the code shows a number of reasons this can happen, such as if the response body length does not match the Content-Length header.
I'm not entirely sure how to fix this, but I would be willing to contribute a PR if someone can suggest a solution. My suggestion would be to change
_raise_from_invalid_response
to replace the message on the exception that is raised with the message from theInvalidResponse
object itself (maybe formatted with''.join(str(s for s in e.args))
).Details
OS type and version: Linux
Python version: Python 2.7.13
google-cloud-python version: 1.4.0 (but code inspection shows this still exists):
Stacktrace:
Steps to reproduce
The text was updated successfully, but these errors were encountered: