question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multipart mixed responses generate warnings

See original GitHub issue

If you read a multipart/mixed response, the connectionpool issues a couple of warnings about defects in the message. I’m not sure what the expected, correct behavior is, but these warnings seem spurious.

Stick this perl script somewhere:

#!/usr/bin/perl

print "Server: Some Server Name\r\n";
print "Content-Type: multipart/mixed; boundary=36eeb8c4e26d842a\r\n";
print "Content-Length: 178\r\n";
print "\r\n\r\n";
print "--36eeb8c4e26d842a\r\n";
print "Content-Type: text/plain\r\n";
print "\r\n";
print "7\r\n";
print "--36eeb8c4e26d842a\r\n";
print "Content-Type: text/plain\r\n";
print "\r\n";
print "9\r\n";
print "--36eeb8c4e26d842a\r\n";
print "Content-Type: text/plain\r\n";
print "\r\n";
print "11\r\n";
print "--36eeb8c4e26d842a--\r\n";

Read it with requests (naturally, you’ll have to change the URI to wherever you put the script):

import requests, logging

logging.basicConfig(level=logging.WARNING)
logging.getLogger("requests").setLevel(logging.DEBUG)

headers = {'accept': "multipart/mixed"}
r = requests.get("http://localhost:8124/cgi-bin/mpm.pl", headers=headers)

print(r)

The following errors are displayed:

DEBUG:requests.packages.urllib3.connectionpool:"GET http://localhost:8124/cgi-bin/mpm.pl HTTP/1.1" 200 178
WARNING:requests.packages.urllib3.connectionpool:Failed to parse headers (url=http://localhost:8888/http://localhost:8124/cgi-bin/mpm.pl): [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()], unparsed data: ''
Traceback (most recent call last):
  File "/home/ndw/.virtualenvs/pyapi/lib/python3.4/site-packages/requests-2.8.0-py3.4.egg/requests/packages/urllib3/connectionpool.py", line 390, in _make_request
    assert_header_parsing(httplib_response.msg)
  File "/home/ndw/.virtualenvs/pyapi/lib/python3.4/site-packages/requests-2.8.0-py3.4.egg/requests/packages/urllib3/util/response.py", line 58, in assert_header_parsing
    raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)
requests.packages.urllib3.exceptions.HeaderParsingError: [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()], unparsed data: ''

It took me quite a while to work out that they were spurious (because in real life, the server side that is generating the multipart/mixed is more complicated!)

See also kennethreitz/requests#3001

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:15
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

21reactions
Lukasacommented, Apr 17, 2017

As far as I know, yes.

6reactions
sethmlarsoncommented, Sep 3, 2020

This issue has been solved in master and will be released in v1.26.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multipart mixed responses generate warnings - - Bountysource
If you read a multipart/mixed response, the connectionpool issues a couple of warnings about defects in the message.
Read more >
Browser support of multipart responses - Stack Overflow
I have had HTTP multipart responses working for a stream of JPEG images. ... Just use: Content-type: multipart/x-mixed-replace -- everything ...
Read more >
multipart/mixed content type and boundary refused by Amavis
I'm writing a Ruby script that send SMTP email. The email is divided onto 3 parts: headers, body and attachment. Unfortunatly, I'm struggling...
Read more >
/Mixed-ing it up: Multipart/Mixed Messages and You ...
Multipart /Mixed, according to RFC 1521, means that the parts are completely independent of each other (not related to each other) but that...
Read more >
Parsing multipart/mixed response in Spring Webclient - Medium
Uploading multipart data is very common nowadays. It is a http format which lets you attach multiple files to the request body of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found