sookasa / box.py

Python client for Box
43 stars 25 forks source link

ValueError thrown when running the example from the README #5

Closed mattrowe closed 10 years ago

mattrowe commented 10 years ago

When I run the "upload" example from the README:

>>> from box import BoxClient
>>> from StringIO import StringIO
>>> client = BoxClient('<valid access token>')
>>> client.upload_file('hello.txt', StringIO('hello world'))

The following traceback is thrown:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/lib/python2.7/site-packages/box/client.py", line 531, in upload_file
    result = self._request("post", "files/content", endpoint="upload", data=form, files={filename: fileobj})
  File "/lib/python2.7/site-packages/box/client.py", line 304, in _request
    response = requests.request(method, url, params=params, data=data, headers=headers, **kwargs)
  File "/lib/python2.7/site-packages/requests-1.2.3-py2.7.egg/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/lib/python2.7/site-packages/requests-1.2.3-py2.7.egg/requests/sessions.py", line 324, in request
    prep = req.prepare()
  File "/lib/python2.7/site-packages/requests-1.2.3-py2.7.egg/requests/models.py", line 225, in prepare
    p.prepare_body(self.data, self.files)
  File "/lib/python2.7/site-packages/requests-1.2.3-py2.7.egg/requests/models.py", line 385, in prepare_body
    (body, content_type) = self._encode_files(files, data)
  File "/lib/python2.7/site-packages/requests-1.2.3-py2.7.egg/requests/models.py", line 99, in _encode_files
    fields = to_key_val_list(data or {})
  File "/lib/python2.7/site-packages/requests-1.2.3-py2.7.egg/requests/utils.py", line 136, in to_key_val_list
    raise ValueError('cannot encode objects that are not 2-tuples')
ValueError: cannot encode objects that are not 2-tuples
tals commented 10 years ago

eeep! It broke in 1.2 which was released yesterday. I'll land a fix soon.

In the meantime you can use 1.1. Sorry about that :(

tals commented 10 years ago

Fixed by 59fdbc9, and it's available as 1.2.1.

Thanks for catching that, and sorry for the inconvenience :)