The error is because your data
parameter is a string.
in models.py::send()
:
# Multi-part file uploads.
if self.files:
(body, content_type) = self._encode_files(self.files)
in models.py::_encode_files()
:
fields = to_key_val_list(self.data)
files = to_key_val_list(files)
In utils.py::to_key_val_list()
:
if isinstance(value, (str, bytes, bool, int)):
raise ValueError('cannot encode objects that are not 2-tuples')
This is getting hit on the call with self.data. You're passing in a string representation of a dictionary, but it's expecting a dictionary itself, like so:
requests.post('http://localhost:8080',
files={'spot[photo]': open('test.jpg', 'rb')},
data={'spot': 'spot_description'})
So, if anything is assigned to the files param, then the data param cannot be of type str, bytes, bool, or int. You can follow along in the source code: https://github.com/kennethreitz/requests/blob/master/requests/models.py#L531