You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using the client to upload a file using FormData, almost exactly the same code as shown in this example. The main difference is that I am passing a file created by tempfile.TemporaryFile as the second argument to add_field.
The result is: TypeError: Can not serialize value type: <class '_io.BufferedRandom'> headers: {'Content-Type': 'application/vnd.ms-excel'} value: <_io.BufferedRandom name=23>
The root exception is actually thrown from helpers.guess_filename: TypeError: 'int' object is not subscriptable
Expected behaviour
There should be no need to call guess_filename because I specified a filename: form.add_field('file', data, filename=filename, content_type=content_type)
And even if I didn't provide a filename, guess_filename should not throw an exception if name is not a string (which is apparently the case for tempfiles; notice that my tempfile has the number 23 for a name).
Actual behaviour
FormData._gen_form_data is not passing the filename to payload.get_payload, even though the filename is available. It seems like the code could be changed to include filename=dispparams.get('filename') in the kwargs for get_payload.
guess_filename assumes that name will be a string. Oddly enough, sometimes it's a number.
Steps to reproduce
Here is my code that produces the error. data is a tempfile.TemporaryFile(). The exception is thrown from the post call. url, filename, and content_type are all valid strings.
Upon further inspection, it looks like it doesn't matter that FormData._gen_form_data doesn't pass the filename to get_payload. The filename is saved with a call to part.set_content_disposition a few lines later. As long as guess_filename doesn't blow up everything is fine.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new
I am using the client to upload a file using
FormData
, almost exactly the same code as shown in this example. The main difference is that I am passing a file created by tempfile.TemporaryFile as the second argument toadd_field
.The result is:
TypeError: Can not serialize value type: <class '_io.BufferedRandom'> headers: {'Content-Type': 'application/vnd.ms-excel'} value: <_io.BufferedRandom name=23>
The root exception is actually thrown from
helpers.guess_filename
:TypeError: 'int' object is not subscriptable
Expected behaviour
There should be no need to call
guess_filename
because I specified a filename:form.add_field('file', data, filename=filename, content_type=content_type)
And even if I didn't provide a filename,
guess_filename
should not throw an exception ifname
is not a string (which is apparently the case for tempfiles; notice that my tempfile has the number 23 for a name).Actual behaviour
FormData._gen_form_data
is not passing the filename topayload.get_payload
, even though the filename is available. It seems like the code could be changed to includefilename=dispparams.get('filename')
in the kwargs forget_payload
.guess_filename
assumes thatname
will be a string. Oddly enough, sometimes it's a number.Steps to reproduce
Here is my code that produces the error.
data
is atempfile.TemporaryFile()
. The exception is thrown from thepost
call.url
,filename
, andcontent_type
are all valid strings.Workaround
Your environment
Python 3.6.1 on Ubuntu
The text was updated successfully, but these errors were encountered: