From dc13631485efcb8b9f533b9a55d4f98c50a3d37b Mon Sep 17 00:00:00 2001 From: "Nam T. Nguyen" Date: Tue, 1 Dec 2015 10:18:56 -0800 Subject: Default to octet-stream if mimetype detection fails. The function mimetypes.guess_type returns (None, None) if it fails to find a matching extension. In that case, we should just treat the media as application/octet-stream. --- googleapiclient/http.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'googleapiclient') diff --git a/googleapiclient/http.py b/googleapiclient/http.py index 41daedcdf..10559c5e5 100644 --- a/googleapiclient/http.py +++ b/googleapiclient/http.py @@ -425,7 +425,11 @@ class MediaFileUpload(MediaIoBaseUpload): self._filename = filename fd = open(self._filename, 'rb') if mimetype is None: - (mimetype, encoding) = mimetypes.guess_type(filename) + # No mimetype provided, make a guess. + mimetype, _ = mimetypes.guess_type(filename) + if mimetype is None: + # Guess failed, use octet-stream. + mimetype = 'application/octet-stream' super(MediaFileUpload, self).__init__(fd, mimetype, chunksize=chunksize, resumable=resumable) -- cgit v1.2.3