'Failed to parse headers' warning logged when getting message/rfc822 content
See original GitHub issueI’ve been investigating an issue I’ve recently discovered when retrieving objects from S3. I’ve now tracked it to urllib3; this test case (which I’ve added to urllib3/test/with_dummyserver/test_socketlevel.py) demonstrates it:
class TestOkayHeaders(SocketDummyServerTestCase):
def _test_okay_header_parsing(self, header):
self.start_response_handler((
b'HTTP/1.1 200 OK\r\n'
b'Content-Length: 0\r\n'
) + header + b'\r\n\r\n'
)
pool = HTTPConnectionPool(self.host, self.port, retries=False)
self.addCleanup(pool.close)
with LogRecorder() as logs:
pool.request('GET', '/')
for record in logs:
assert 'Failed to parse headers' not in record.msg
def test_header_text_plain(self):
self._test_okay_header_parsing(b'Content-type: text/plain')
def test_header_message_rfc822(self):
self._test_okay_header_parsing(b'Content-type: message/rfc822')
The test with text/plain passes, while the test with message/rfc822 fails, and this is logged:
Failed to parse headers (url=http://localhost:36732/): Unknown, unparsed data: [<http.client.HTTPMessage object at 0x7f8fab9373c8>]
Traceback (most recent call last):
File "/home/user/git/urllib3/src/urllib3/connectionpool.py", line 396, in _make_request
assert_header_parsing(httplib_response.msg)
File "/home/user/git/urllib3/src/urllib3/util/response.py", line 68, in assert_header_parsing
raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)
urllib3.exceptions.HeaderParsingError: Unknown, unparsed data: [<http.client.HTTPMessage object at 0x7f8fab9373c8>]
While retrieving content of type message/rfc822 still works, the warning message being logged is incorrect and unhelpful.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Issue 29353: Incorrect handling of HTTP response with ...
msg286106 ‑ (view) Author: (brokenenglish) Date: 2017‑01‑23 18:58
msg286110 ‑ (view) Author: R. David Murray (r.david.murray) * Date: 2017‑01‑23 19:44
msg286126 ‑ (view) Author: Martin...
Read more >Delivery Failure creates $RFC822.eml attachment.
Delivery Status Notification (Failure) bounces to our Lotus Notes/Domino server will often return with an attached $RFC822.eml file instead ...
Read more >python - Does requests properly support multipart responses?
To answer your question: Yes, Requests handles multipart requests just fine. Having said that, I have seen the same error you're getting.
Read more >Email Header Analyzer, RFC822 Parser - MxToolbox
This tool will make email headers human readable by parsing them according to RFC 822. Email headers are present on every email you...
Read more >MIME-tools - modules for parsing MIME entities
It contains information from the message header: content type, sender, ... Error messages are only logged if $^W is set true and MIME::Tools...
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 Free
Top 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

Oh I wasn’t going to put in the fix that’s in the issue, that’s just what I dreamt up to be able to see the unit test pass. 😃 I want to bring full coverage to this function for sure so I’ll have to explore that further and research why this code branch was added in the first place.
Doing a quick google search for
unparsed_data python httphas yielded a few StackOverflow questions whereunparsed_datais byte data which is what I assume the original author of this code branch intended but I haven’t found an example where only theunparsed_datais set anddefectsaren’t.for me the backend application to which the url is pointing is directly returning the string I changed it to return Response(response=original_message,status=200, content_type=‘application/text’)
in the start i just returned text like
return original_message
I think this answer works only for my case