diff --git a/mwclient/client.py b/mwclient/client.py index dfa74bb2848c2574c0869e518c58a28c1f98fd69..440d908ad22966888bb94fa9f7c5658c17ef485d 100644 --- a/mwclient/client.py +++ b/mwclient/client.py @@ -511,6 +511,21 @@ class Site(object): postdata = predata files = None if file is not None: + + # Workaround for https://github.com/mwclient/mwclient/issues/65 + # ---------------------------------------------------------------- + # Since the filename in Content-Disposition is not used as the + # destination filename, we can pass in some ascii-only dummy name + # to make sure the server accepts it. + fname = 'upload' + name = getattr(file, 'name', None) + if name and name[0] != '<' and name[-1] != '>' and name.find('.') != -1: + ext = name[name.rfind('.') + 1:] + fname = 'upload.{}'.format(ext) + file = (fname, file) + # End of workaround + # ---------------------------------------------------------------- + files = {'file': file} wait_token = self.wait_token()