From ff0dd8eefedb19c4ce58e9a57e1598ee71b39ed6 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Sat, 6 Dec 2014 21:40:52 +0100 Subject: [PATCH] Patch for an Issue #997 --- thirdparty/multipart/multipartpost.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/thirdparty/multipart/multipartpost.py b/thirdparty/multipart/multipartpost.py index b3ea1eebd..2863b8580 100644 --- a/thirdparty/multipart/multipartpost.py +++ b/thirdparty/multipart/multipartpost.py @@ -88,7 +88,11 @@ class MultipartPostHandler(urllib2.BaseHandler): for (key, fd) in files: file_size = os.fstat(fd.fileno())[stat.ST_SIZE] if isinstance(fd, file) else fd.len filename = fd.name.split('/')[-1] if '/' in fd.name else fd.name.split('\\')[-1] - contenttype = mimetypes.guess_type(filename)[0] or 'application/octet-stream' + try: + contenttype = mimetypes.guess_type(filename)[0] or 'application/octet-stream' + except: + # Reference: http://bugs.python.org/issue9291 + contenttype = 'application/octet-stream' buf += '--%s\r\n' % boundary buf += 'Content-Disposition: form-data; name="%s"; filename="%s"\r\n' % (key, filename) buf += 'Content-Type: %s\r\n' % contenttype