Skip to content
Myr

Encode both keys and values for incoming unicode data as UTF-8, coincidentally fixing a bug that caused UTF-8 encoded byte strings to be encoded twice and causing an UnicodeDecodeError.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Johannes Gorset · committed by Johannes Gorset · parent 59dd3ed · Browse files · 2 files+9 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+9 added−4 removed

  • other:+9 added−4 removed

2 files+9 added−4 removed

modified:requests/core.py+7 added-4 removed
68 unmodified lines
69 self.url = url70 self.headers = headers71 self.files = files72 self.method = method73 73 self.data = data74 self.data = {}75 for (k, v) in data.items():76 self.data.update({77 k.encode('utf-8') if k.__class__ is unicode else k: \78 v.encode('utf-8') if v.__class__ is unicode else v79 })8081 socket.setdefaulttimeout(timeout)8277 for (k, v) in self.data.iteritems():78 self.data[k] = v.encode('utf-8')7983 # url encode data if it's a dict84 if hasattr(data, 'items'):85 self._enc_data = urllib.urlencode(self.data)86 else:
469 unmodified lines
modified:test_requests.py+2 added
139 unmodified lines
140 self.assertEquals(r.status_code, 200)141142 def test_unicode_get(self):143 requests.get('http://google.com', params={'foo': u'føø'})144 requests.get('http://google.com', params={u'føø': u'føø'})145 requests.get('http://google.com', params={'føø': 'føø'})146 requests.get('http://google.com', params={'foo': u'foo'})147 requests.get('http://google.com/ø', params={'foo': u'foo'})148149
2 unmodified lines