Handle invalid upload of text fd more gracefully

This commit is contained in:
Lonami Exo
2019-12-27 12:05:27 +01:00
parent bdb74ac235
commit a142b7de5e
2 changed files with 6 additions and 1 deletions

View File

@@ -500,6 +500,11 @@ class UploadMethods:
if pos is not None:
file.seek(pos)
if not isinstance(data, bytes):
raise TypeError(
'file descriptor returned {}, not bytes (you must '
'open the file in bytes mode)'.format(type(data)))
file = data
file_size = len(file)