malformed multipart form-data

I was trying to use requests to post a form to AWS S3, and continually got an error about malformed multipart/form-data.  I am not an expert on http formatting standards, but I was able to make this work with python posters instead.

Requests should support the option to format as multipart/form-data even without breaking up the file (in my case the files are small, but S3 only support enctype of multipart).

For comparison, here is the  request body that was generated by requests and rejected, below is the accepted request.

```
--b12efdfeadf54d8d9041a03966c7f8d2
Content-Disposition: form-data; name="AWSAccessKeyId"

AKIAJGWMPJUFZ57CRWQQ
--b12efdfeadf54d8d9041a03966c7f8d2
Content-Disposition: form-data; name="success_action_status"

200
--b12efdfeadf54d8d9041a03966c7f8d2
Content-Disposition: form-data; name="acl"

private
--b12efdfeadf54d8d9041a03966c7f8d2
Content-Disposition: form-data; name="key"

${filename}
--b12efdfeadf54d8d9041a03966c7f8d2
Content-Disposition: form-data; name="signature"

hQ2NDqs9SHLoH5RtMQn9cfQITPc=
--b12efdfeadf54d8d9041a03966c7f8d2
Content-Disposition: form-data; name="policy"

eyJjb25kaXRpb25zIjogW1sic3RhcnRzLXdpdGgiLCAiJGtleSIsICIiXSwgeyJhY2wiOiAicHJpdmF0ZSJ9LCB7InN1Y2Nlc3NfYWN0aW9uX3N0YXR1cyI6ICIyMDAifSwgWyJzdGFydHMtd2l0aCIsICIkQ29udGVudC1UeXBlIiwgIiJdLCBbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwgMCwgMTA0ODU3NjAwXSwgeyJidWNrZXQiOiAiZGF0YXN5bmMtdXBsb2FkcyJ9XSwgImV4cGlyYXRpb24iOiAiMjAxNC0xMC0xOFQxMjozMjowMFoifQ==
--b12efdfeadf54d8d9041a03966c7f8d2
Content-Disposition: form-data; name="Content-Type"

application/octet-stream
--b12efdfeadf54d8d9041a03966c7f8d2
Content-Disposition: form-data; name="file"

This line is new

--b12efdfeadf54d8d9041a03966c7f8d2
Content-Disposition: form-data; name="file"

and so is this one

--b12efdfeadf54d8d9041a03966c7f8d2
Content-Disposition: form-data; name="file"

005205   6802  30   13   33.8   3.8  034344 034727  14.1  444982000133517375 0 ???????? 000000

--b12efdfeadf54d8d9041a03966c7f8d2
Content-Disposition: form-data; name="file"; filename="8b8e6cbe185e4d20b7e0586f076bb353.bvs"


--b12efdfeadf54d8d9041a03966c7f8d2--
```

The request body as generated using python poster and urllib2, which was accepted by S3:

```
--a6bf1e61b29f4a3980b62345e64c120f

Content-Disposition: form-data; name="AWSAccessKeyId"

Content-Type: text/plain; charset=utf-8



AKIAJGWMPJUFZ57CRWQQ

--a6bf1e61b29f4a3980b62345e64c120f

Content-Disposition: form-data; name="success_action_status"

Content-Type: text/plain; charset=utf-8



200

--a6bf1e61b29f4a3980b62345e64c120f

Content-Disposition: form-data; name="acl"

Content-Type: text/plain; charset=utf-8



private

--a6bf1e61b29f4a3980b62345e64c120f

Content-Disposition: form-data; name="key"

Content-Type: text/plain; charset=utf-8



${filename}

--a6bf1e61b29f4a3980b62345e64c120f

Content-Disposition: form-data; name="signature"

Content-Type: text/plain; charset=utf-8



BOanSb+x9yE0rx+Y08C7OC1bTZM=

--a6bf1e61b29f4a3980b62345e64c120f

Content-Disposition: form-data; name="policy"

Content-Type: text/plain; charset=utf-8



eyJjb25kaXRpb25zIjogW1sic3RhcnRzLXdpdGgiLCAiJGtleSIsICIiXSwgeyJhY2wiOiAicHJpdmF0ZSJ9LCB7InN1Y2Nlc3NfYWN0aW9uX3N0YXR1cyI6ICIyMDAifSwgWyJzdGFydHMtd2l0aCIsICIkQ29udGVudC1UeXBlIiwgIiJdLCBbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwgMCwgMTA0ODU3NjAwXSwgeyJidWNrZXQiOiAiZGF0YXN5bmMtdXBsb2FkcyJ9XSwgImV4cGlyYXRpb24iOiAiMjAxNC0xMC0xOFQxMjowNDowMFoifQ==

--a6bf1e61b29f4a3980b62345e64c120f

Content-Disposition: form-data; name="Content-Type"

Content-Type: text/plain; charset=utf-8



application/octet-stream

--a6bf1e61b29f4a3980b62345e64c120f

Content-Disposition: form-data; name="file"; filename="C:/somedirectory/8b8e6cbe185e4d20b7e0586f076bb353.bvs"

Content-Type: text/plain; charset=utf-8



This line is new

and so is this one

005205   6802  30   13   33.8   3.8  034344 034727  14.1  444982000133517375 0 ???????? 000000



--a6bf1e61b29f4a3980b62345e64c120f--
```


Can you tell us what you're using to generate the last part of data where you're getting different form fields? (The part that generated the "This line is new..." data.) Without that we have no way of helping you.


That is simply a text file that was opened like `open(filename, 'rb')`.  It is opened immediately before passing it to requests. as `requests.post(url, data=dat, files={'file':file_obj}, enctype='multipart/form-data)` . This is pseudo code, I have since removed requests from that portion of the code, and have it working with another library. I am no longer in need of a solution, but I think this is bug in the way requests handles encoding.

This is the data in the text file:

```
This line is new
and so is this one
005205   6802  30   13   33.8   3.8  034344 034727  14.1  444982000133517375 0 ???????? 000000
```