Fails to decode a header that requests can handle
See original GitHub issueI am trying to read this url
https://www.bitstamp.net/api/v2/trading-pairs-info/
It fails (see https://github.com/theelous3/asks/issues/60) with an exception:
....
File "/Users/michael/.pyenv/versions/3.6.3/lib/python3.6/site-packages/h11/_readers.py", line 85, in maybe_read_from_SEND_RESPONSE_server
return class_(headers=list(_decode_header_lines(lines[1:])),
File "/Users/michael/.pyenv/versions/3.6.3/lib/python3.6/site-packages/h11/_readers.py", line 55, in _decode_header_lines
matches = validate(header_field_re, line)
File "/Users/michael/.pyenv/versions/3.6.3/lib/python3.6/site-packages/h11/_util.py", line 96, in validate
raise LocalProtocolError(msg)
Looking closer, this is the header that seems to cause trouble:
bytearray(b'Set-Cookie: ___utmvafIumyLc=kUd\x01UpAt; path=/; Max-Age=900')
My guess is it’s the \x
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (10 by maintainers)
Top Results From Across the Web
unable to decode Python web request - Stack Overflow
Python is unable to decode the web request. Web request is successful with code - 200. Here is the code below import requests...
Read more >Can't read 'data' object returned … | Apple Developer Forums
I am learning to use Swift and am trying to request data from the USDA Food Data ... and I can read the...
Read more >HTTP/1.1: Header Field Definitions
The Accept request-header field can be used to specify certain media types which are acceptable for the response. Accept headers can be used...
Read more >RFC 7231: Hypertext Transfer Protocol (HTTP/1.1)
This document defines the semantics of HTTP/1.1 messages, as expressed by request methods, request header fields, response status codes, and response header ......
Read more >Getting started with httr
You can automatically throw a warning or raise an error if a request did not ... httr will automatically decode content from the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Note that curl allows all sorts of things specifically because it is a tool used for pentesting and verification. It would be nice if it had some sort of validation mode that highlighted spec errors.
On further thought, I realized my suggestion above wouldn’t actually handle the case that started this, because there the offending byte is inside a cookie, which means that the client has to be able to send it back to the server 😕. So I guess our options are:
Loosen the header-value regex to accept any character except
\0
,\r
,\n
Be spec-compliant about what we send and receive in server mode, but use the loosened rule above in client mode. This would be somewhat annoying to implement, though, because of how h11 is structured (the same
h11.Request
orh11.Response
objects are used by both clients and servers, they validate headers, and they don’t know which role we’re playing – if we were only changing the rules for parsing from the wire, that would be easier, because that’s done by the connection object itself).So I guess I’m now leaning towards the first option.