From 6d23079f1fdd07f66b03d3850ee2a1d052b7b915 Mon Sep 17 00:00:00 2001 From: carlcarl Date: Sat, 14 May 2016 22:06:41 +0800 Subject: [PATCH] Use utf-8 instead of ASCII encoding --- imgurup/__init__.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/imgurup/__init__.py b/imgurup/__init__.py index d149926..857d9f6 100755 --- a/imgurup/__init__.py +++ b/imgurup/__init__.py @@ -516,23 +516,23 @@ def get_content_type(filename): def encode_field(field_name): return ( - ('--' + boundary).encode('ASCII'), + ('--' + boundary).encode('utf-8'), ('Content-Disposition: form-data; name="%s"' % ( field_name - )).encode('ASCII'), - b'', data[field_name].encode('ASCII') + )).encode('utf-8'), + b'', data[field_name].encode('utf-8') ) def encode_file(field_name): filename = files[field_name] return ( - ('--' + boundary).encode('ASCII'), + ('--' + boundary).encode('utf-8'), ('Content-Disposition: form-data; name="%s"; filename="%s"' % ( field_name, filename - )).encode('ASCII'), + )).encode('utf-8'), ('Content-Type: %s' % ( get_content_type(filename) - )).encode('ASCII'), + )).encode('utf-8'), b'', open(filename, 'rb').read() ) @@ -542,8 +542,8 @@ def encode_file(field_name): lines.extend(encode_field(name)) for name in files: lines.extend(encode_file(name)) - lines.extend((('--%s--' % boundary).encode('ASCII'), b'')) - body = '\r\n'.encode('ASCII').join(lines) + lines.extend((('--%s--' % boundary).encode('utf-8'), b'')) + body = '\r\n'.encode('utf-8').join(lines) headers = { 'content-type': 'multipart/form-data; boundary=' + boundary,