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
Getting exception in _update_chunk_length #1516
Comments
Is this URL publicly available? I'd like to see the exact HTTP response. |
Yes, I faced this issue while requesting an URL for wikidata entry, not sure what's the exact URL because this happened after ~94000th iteration. |
If you could get the exact URL where this happens that'd be great. The URL you've given as an example doesn't use >>> import urllib3
>>> p = urllib3.PoolManager()
>>> r = p.request('GET', 'https://commons.wikimedia.org/wiki/File:Belfast_City_Hall_2.jpg', preload_content=False)
>>> [x for x in r.read_chunked()]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda3\lib\site-packages\urllib3\response.py", line 647, in read_chunked
"Response is not chunked. "
urllib3.exceptions.ResponseNotChunked: Response is not chunked. Header 'transfer-encoding: chunked' is missing. |
I'm having this problem as well, but my webpage isn't public and its contents are sensitive. On a request that succeeds (e.g. from Chrome), the response headers look like this:
but unfortunately I can't see the chunks in Chrome and it's a TLS request so sniffing on the wire is hard. Not being able to see the chunks, I won't opine on whether this is "really a bug." |
Is there a way you can get curl to show the chunks? You can remove all the content we just need the boundaries and how much data is between them. If you've got a reliable reproducer we would love to see it. :) |
I stepped through urllib3 during the read. The server was returning a 500. The response headers said it was chunked but it wasn't -- I believe the body was empty. So in my case this wasn't a bug in urllib3; the server definitely sent a spec-violating response. I'm just going to leave this here to remind other folks that an "incomplete read" may be because the data was never written. |
Could this be caught in urllib3 and re-raised with a "The server indicated a chunked response. Did the server send a non-chunked response or no chunks at all?" wrapper exception? ValueError is less than ideal to indicate a protocol error. In my case and issue 4248 above, I'm going to guess that the body was empty; 4248 had another response on the connection while @shivam05011996 and I did not. I'd suggest that the wrapper exception contain the HTTP response code since that might help diagnose a broken server. |
I was thinking about this as well. In the original post, we clearly have a response we could attach. Perhaps |
We ran into a similar issue, it turned out to be an issue on the server side that it cannot properly compress and chunk. We got a workaround that passing |
I am able to reproduce the same bug by using this code import requests I think this is a bug in the server side, but maybe urllib3 could do a better job workarounding this bug in the server, as other libraries / applications do for example (same URL works ok in a web browser like chrome or firefox ...) This is traceback I get when it fails: During handling of the above exception, another exception occurred: Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): During handling of the above exception, another exception occurred: Traceback (most recent call last): |
As far as I could see, the server (in the example above) sends chunked transfer, but it does not send properly the last 0-length chunk and returns the response code. That's where urllib3 raises exception when trying to decode the length of the chunk from the response status code line. Some insights I could find so far:
r = requests.get('https://www.telecreditobcp.com/tlcnp/index.do', stream=True)
curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding |
Some more insights:
openssl s_client -connect www.telecreditobcp.com:443 -servername www.telecreditobcp.com then send this GET /tlcnp/index.do HTTP/1.1 |
Ok, I confirmed this is a bug in openssl 1.1 versions, working in openssl 1.0 |
@mbatle Thank you, for digging in deeper on this issue, if not required, please go ahead and close this issue. |
@mbatle I guess I should be watching openssl/openssl#9360 ? |
i got exactly the same bug in a HTTP request, so i think it's not about openssl |
This exception is raised when urllib3 is expecting a next chunk from the
server but the server doesn't provide a validly encoded chunk and instead
provides something else.
AFAIK the cause of this is never that urllib3 is *erroneously* expecting a
next chunk, or that its chunk parsing is buggy. (If such a cause does
exist, I haven't encountered it on any of the related issues.)
Instead there are various other causes: an openssl bug, a bug in the server
itself, etc. Using a proxy (such as a VPN but any proxy would do) often
causes the bug to go away, since the proxy re-encodes the chunks.
There is a bug in urllib3 though: this exception is very unhelpfully named,
and also it's arguable that server protocol errors shouldn't raise an
exception in the client code but instead signal some other type of error.
…On Wed, Feb 19, 2020 at 11:34 PM Zenk Ju ***@***.***> wrote:
i got exactly the same bug in a HTTP request, so i think it's not about
openssl
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1516?email_source=notifications&email_token=AAVWYJJF5IW2IP26XZB5UTLRDYXABA5CNFSM4GO5HSN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMLJCWY#issuecomment-588681563>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAVWYJIVUDZGWAIWGZXG7BDRDYXABANCNFSM4GO5HSNQ>
.
|
I get the same exception here with headers [Transfer-Encoding] : chunked. finally i add a line as tell in the #4248 I cannot give you the Url it is a private server. |
I ran into the same issue with yet another private service. In my case the issue is that the server sends "Transfer-Encoding: chunked" in a 204 NO CONTENT response to a PUT request. The server then follows RFC7230 section 3.3.3 point 1, and does not send any message body - in particular it does not send even the chunk length, which urllib3 expects to receive. The RFC seems to be somewhat ambiguous, and the urllib3 behaviour is understandable in view of section 3.3.3 point 3. curl used to have the same issue, but it was fixed in this commit: http: don't parse body-related headers bodyless responses Should urllib3 follow the same logic as curl here, and ignore the header fields Content-Encoding, Content-Length, Content-Range, Last-Modified and Transfer-Encoding whenever the response is supposed to be bodyless? |
I agree most of those should be ignored, along with zero Content-Length. If
a nonzero Content-Length is given I think it should be consumed or raise an
exception, one or the other.
…On Tue, Jun 9, 2020 at 4:44 AM h-rummukainen ***@***.***> wrote:
I ran into the same issue with yet another private service.
In my case the issue is that the server sends "Transfer-Encoding: chunked"
in a 204 NO CONTENT response to a PUT request. The server then follows
RFC7230 section 3.3.3 point 1, and does not send any message body - in
particular it does not send even the chunk length, which urllib3 expects to
receive. The RFC seems to be somewhat ambiguous, and the urllib3 behaviour
is understandable in view of section 3.3.3 point 3.
curl used to have the same issue, but it was fixed in this commit: http:
don't parse body-related headers bodyless responses
<curl/curl@2e5ceb3>
Should urllib3 follow the same logic as curl here, and ignore the header
fields Content-Encoding, Content-Length, Content-Range, Last-Modified and
Transfer-Encoding whenever the response is supposed to be bodyless?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1516 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAVWYJIQ4D7EQR46LBP7YLDRVYOBFANCNFSM4GO5HSNQ>
.
|
Hi,
While requesting a particular URL, I came across this error
This was reported in requests module here
I fixed it as -
or a one liner as
Is it worth giving a PR regarding this??
The text was updated successfully, but these errors were encountered: