multipart/form-data and datetime data

I raise an bug that you already fix in the past on this issue : https://github.com/kennethreitz/requests/issues/661 or https://github.com/kennethreitz/requests/issues/737

I tried the same methodology with that code :

```
import requets

requests.post("http://httpbin.org/post", data={'a': 0})
requests.post("http://httpbin.org/post", data={'a': 0.0})
requests.post("http://httpbin.org/post", data={'a': 0}, files={'b': 'foo'})
requests.post("http://httpbin.org/post", data={'a': 0.0}, files={'b': 'foo'})
```

With the 1.2.0 version, no error is raised.

With 1.2.3 version, I have that traceback :

```
Traceback (most recent call last):
  File "test.py", line 8, in <module>
    requests.post("http://httpbin.org/post", data={'a': 0.0}, files={'b': 'foo'})
  File ".../dev/lib/python2.7/site-packages/requests/api.py", line 88, in post
    return request('post', url, data=data, **kwargs)
  File ".../dev/lib/python2.7/site-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File ".../dev/lib/python2.7/site-packages/requests/sessions.py", line 324, in request
    prep = req.prepare()
  File ".../dev/lib/python2.7/site-packages/requests/models.py", line 225, in prepare
    p.prepare_body(self.data, self.files)
  File ".../dev/lib/python2.7/site-packages/requests/models.py", line 385, in prepare_body
    (body, content_type) = self._encode_files(files, data)
  File ".../dev/lib/python2.7/site-packages/requests/models.py", line 133, in _encode_files
    body, content_type = encode_multipart_formdata(new_fields)
  File ".../dev/lib/python2.7/site-packages/requests/packages/urllib3/filepost.py", line 90, in encode_multipart_formdata
    body.write(data)
TypeError: 'float' does not have the buffer interface
```

My original problem was with a python datetime in the data dict
Thanks,


Hi @ppavril, thanks for raising this issue!

So the problem here is that we don't ask for a string representation of keys or values. I think the correct fix is changing the following code (at [line 102 of models.py](https://github.com/kennethreitz/requests/blob/master/requests/models.py#L102)) from:

``` python
for field, val in fields:
    if isinstance(val, basestring) or not hasattr(val, '__iter__'):
        val = [val]
    for v in val:
        if v is not None:
            new_fields.append(
                (field.decode('utf-8') if isinstance(field, bytes) else field,
                 v.encode('utf-8') if isinstance(v, str) else v))
```

to:

``` python
for field, val in fields:
    if isinstance(val, basestring) or not hasattr(val, '__iter__'):
        val = [val]
    for v in val:
        if v is not None:
            if not isinstance(v, basestring):
                v = str(v)

            new_fields.append(
                (field.decode('utf-8') if isinstance(field, bytes) else field,
                 v.encode('utf-8') if isinstance(v, str) else v))
```

However, this is a breaking API change (we now coerce non-string types in the data dict), so should become part of #1459. We should also take advantage of that to clean this section of code up, because it's not totally easy to follow.

In the meantime @ppavril, you can work around this by calling `str()` on all your data values before passing them to Requests.


Thank you for your quick answer.
I think remaining on 1.2.0 version now and look at your improvements and chagement when I'll upgrade.
Thanks,


Funny thing. I misread @Lukasa's snippet and typed out this whole response as to why it was not optimal then looked at it again and deleted it. :-) 


I rewrote that snippet twice. =P


Implemented in #1537.