From f4d4698afd9ac48b4f33fffd3e96ce7ab3ec63a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Michael=20O=2E=20Hegg=C3=B8?= <danmichaelo@gmail.com> Date: Sun, 23 Nov 2014 19:30:40 +0100 Subject: [PATCH] [#65] Workaround for non-ascii filename uploads Quite silly, but until the problem is fixed on the server side, it seems like this workaround is the best solution there is. --- mwclient/client.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mwclient/client.py b/mwclient/client.py index dfa74bb..440d908 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() -- GitLab