From b3b2b192127b02984e201176a3eda040d480ee8f Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 25 Feb 2011 07:39:19 -0500 Subject: [PATCH] hmmm --- requests/core.py | 13 +++++++------ test_requests.py | 20 +++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/requests/core.py b/requests/core.py index 948b23e4..13dc5c43 100644 --- a/requests/core.py +++ b/requests/core.py @@ -165,13 +165,14 @@ class Request(object): else: if self.files: register_openers() +# self.files datagen, headers = multipart_encode(self.files) req = _Request(self.url, data=datagen, headers=headers, method=self.method) else: req = _Request(self.url, method=self.method) - if self.data: - req.data = self.data + if self.data: + req.data = self.data if self.headers: req.headers = self.headers @@ -399,11 +400,11 @@ def request(method, url, **kwargs): :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload. :param auth: (optional) AuthObject to enable Basic HTTP Auth. """ - data = kwargs.get('data', None) or kwargs.get('params', None) + data = kwargs.pop('data', dict()) or kwargs.pop('params', dict()) - r = Request(method=method, url=url, data=data, headers=kwargs.get('headers', {}), - cookiejar=kwargs.get('cookies', None), files=kwargs.get('files', None), - auth=kwargs.get('auth', auth_manager.get_auth(url))) + r = Request(method=method, url=url, data=data, headers=kwargs.pop('headers', {}), + cookiejar=kwargs.pop('cookies', None), files=kwargs.pop('files', None), + auth=kwargs.pop('auth', auth_manager.get_auth(url))) r.send() return r.response diff --git a/test_requests.py b/test_requests.py index 5910d879..51d103df 100644 --- a/test_requests.py +++ b/test_requests.py @@ -63,14 +63,20 @@ class RequestsTestSuite(unittest.TestCase): requests.auth_manager.empty() def test_POSTBIN_GET_POST_FILES(self): - bin = requests.get('http://www.postbin.org/') - self.assertEqual(bin.status_code, 200) + h = {'Content-type': 'application/x-www-form-urlencoded'} + + bin = requests.post('http://www.postbin.org/', headers=h) + # self.assertEqual(bin.status_code, 200) + + print bin.url + print bin.status_code - post = requests.post(bin.url, data={'some': 'data'}) - self.assertEqual(post.status_code, 200) + # post = requests.post(bin.url, data={'some': 'data'}) + # self.assertEqual(post.status_code, 200) - post2 = requests.post(bin.url, files={'some': open('test_requests.py')}) - self.assertEqual(post2.status_code, 200) + # post2 = requests.post(bin.url, files={'some': open('test_requests.py')}) + # self.assertEqual(post2.status_code, 200) + def test_POSTBIN_GET_POST_FILES_WITH_PARAMS(self): # TODO: postbin w/ params @@ -80,7 +86,7 @@ class RequestsTestSuite(unittest.TestCase): post = requests.post(bin.url, data={'some': 'data'}) self.assertEqual(post.status_code, 200) - # post2 = requests.post(bin.url, files={'some': open('test_requests.py')}, data={'some': 'data'}) + post2 = requests.post(bin.url, files={'some': open('test_requests.py')}, data={'some': 'data'}) # self.assertEqual(post2.status_code, 200) def test_nonzero_evaluation(self):