mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
hmmm
This commit is contained in:
+7
-6
@@ -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
|
||||
|
||||
+13
-7
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user