Skip to content
Myr

Merge pull request #29 from meganemura/requests

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

--- raised Attribute Error when post str data something like json because of not having items attribute. move encoding data to utf-8 inside hasattr(data, items)

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 912f48e, 1971bdb · Browse files · 2 files+9 added−7 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−7 removed

  • other:+9 added−7 removed

2 files+9 added−7 removed

modified:requests/core.py+6 added-7 removed
67 unmodified lines
68 self.url = url69 self.headers = headers70 self.files = files71 self.method = method7272 self.data = {}74 for (k, v) in data.items():75 self.data.update({76 k.encode('utf-8') if isinstance(k, unicode) else k:77 v.encode('utf-8') if isinstance(v, unicode) else v78 })7374 socket.setdefaulttimeout(timeout)7582 # url encode data if it's a dict76 if hasattr(data, 'items'):77 for (k, v) in data.items():78 self.data.update({79 k.encode('utf-8') if isinstance(k, unicode) else k:80 v.encode('utf-8') if isinstance(v, unicode) else v81 })82 # url encode data if it's a dict83 self._enc_data = urllib.urlencode(self.data)84 else:85 self._enc_data = self.data86
473 unmodified lines
modified:test_requests.py+3 added
77 unmodified lines
7879 post2 = requests.post(bin.url, files={'some': open('test_requests.py')})80 self.assertEqual(post2.status_code, 201)8182 post3 = requests.post(bin.url, data='[{"some": "json"}]')83 self.assertEqual(post.status_code, 201)8485 def test_POSTBIN_GET_POST_FILES_WITH_PARAMS(self):86 bin = requests.post('http://www.postbin.org/')8788 self.assertEqual(bin.status_code, 200)
66 unmodified lines