From 52f587827d03ee4b31a082f9997d9e6aa356cbf0 Mon Sep 17 00:00:00 2001 From: jjrylearn Date: Sat, 8 Dec 2018 19:55:55 -0500 Subject: [PATCH] Url encode all strings, not just unicode --- unirest/utils.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/unirest/utils.py b/unirest/utils.py index fc1fef8..47f7b4c 100644 --- a/unirest/utils.py +++ b/unirest/utils.py @@ -1,11 +1,9 @@ from poster.encode import multipart_encode import urllib -def to_utf8(value): - if isinstance(value, unicode): - return urllib.quote_plus(value.encode('utf-8')) - return value +def to_encoded_utf8(value): + return urllib.quote_plus(value.encode('utf-8')) def _dictionary_encoder(key, dictionary): @@ -13,9 +11,9 @@ def _dictionary_encoder(key, dictionary): for k, v in dictionary.iteritems(): if type(v) is file: continue - key = to_utf8(key) - k = to_utf8(k) - v = to_utf8(v) + key = to_encoded_utf8(key) + k = to_encoded_utf8(k) + v = to_encoded_utf8(v) result.append('{}[{}]={}'.format(key, k, v)) return result @@ -35,8 +33,8 @@ def dict2query(dictionary): nested_query = encoders[v.__class__](k, v) query += nested_query else: - key = to_utf8(k) - value = to_utf8(v) + key = to_encoded_utf8(k) + value = to_encoded_utf8(v) query.append('{}={}'.format(key, value)) return '&'.join(query)