From 6648defcddeff2e5e4022f51a9fd7b6c224bc472 Mon Sep 17 00:00:00 2001 From: Christopher Peplin Date: Sat, 18 Jul 2015 18:50:29 -0400 Subject: [PATCH 1/3] Fix docs for passing a list of values for a query string The special `[]` notation at the end of the field name is not necessary to get a field to appear with multiple values in the query string. --- docs/user/quickstart.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index cac4ace0..42202648 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -73,13 +73,12 @@ You can see that the URL has been correctly encoded by printing the URL:: Note that any dictionary key whose value is ``None`` will not be added to the URL's query string. -In order to pass a list of items as a value you must mark the key as -referring to a list like string by appending ``[]`` to the key:: +You can also pass a list of items as a value:: - >>> payload = {'key1': 'value1', 'key2[]': ['value2', 'value3']} + >>> payload = {'key1': 'value1', 'key2': ['value2', 'value3']} >>> r = requests.get("http://httpbin.org/get", params=payload) >>> print(r.url) - http://httpbin.org/get?key1=value1&key2%5B%5D=value2&key2%5B%5D=value3 + http://httpbin.org/get?key1=value1&key2=value2&key2=value3 Response Content ---------------- From e8a4784c8fa8cb137c6d1c102059f0b2f501c175 Mon Sep 17 00:00:00 2001 From: Matej Stuchlik Date: Tue, 4 Aug 2015 15:05:35 +0200 Subject: [PATCH 2/3] Mention SNI being backported to Python2.7.9 in FAQ That happened as part of PEP 466 - "Network Security Enhancements for Python 2.7" --- docs/community/faq.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/community/faq.rst b/docs/community/faq.rst index c5daee46..f869ee9a 100644 --- a/docs/community/faq.rst +++ b/docs/community/faq.rst @@ -79,9 +79,9 @@ when servers are using `Virtual Hosting`_. When such servers are hosting more than one SSL site they need to be able to return the appropriate certificate based on the hostname the client is connecting to. -Python3's SSL module includes native support for SNI. This support has not been -back ported to Python2. For information on using SNI with Requests on Python2 -refer to this `Stack Overflow answer`_. +Python3 and Python 2.7.9+ include native support for SNI in their SSL modules. +For information on using SNI with Requests on Python < 2.7.9 refer to this +`Stack Overflow answer`_. .. _`Server-Name-Indication`: https://en.wikipedia.org/wiki/Server_Name_Indication .. _`virtual hosting`: https://en.wikipedia.org/wiki/Virtual_hosting From 276202f51ee9967969eafc1880c4785c80d63d3b Mon Sep 17 00:00:00 2001 From: Akira J Date: Tue, 4 Aug 2015 22:47:12 +0100 Subject: [PATCH 3/3] Fix merge setting for not preserving original order of dict parameters --- requests/sessions.py | 4 +--- test_requests.py | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/requests/sessions.py b/requests/sessions.py index 820919ee..31844eb8 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -63,12 +63,10 @@ def merge_setting(request_setting, session_setting, dict_class=OrderedDict): merged_setting.update(to_key_val_list(request_setting)) # Remove keys that are set to None. - for (k, v) in request_setting.items(): + for (k, v) in merged_setting.items(): if v is None: del merged_setting[k] - merged_setting = dict((k, v) for (k, v) in merged_setting.items() if v is not None) - return merged_setting diff --git a/test_requests.py b/test_requests.py index a5d63464..7e5e4d8f 100755 --- a/test_requests.py +++ b/test_requests.py @@ -125,6 +125,13 @@ class RequestsTestCase(unittest.TestCase): "http://example.com/path?key=value#fragment", params={"a": "b"}).prepare() assert request.url == "http://example.com/path?key=value&a=b#fragment" + def test_params_original_order_is_preserved_by_default(self): + param_ordered_dict = collections.OrderedDict((('z', 1), ('a', 1), ('k', 1), ('d', 1))) + session = requests.Session() + request = requests.Request('GET', 'http://example.com/', params=param_ordered_dict) + prep = session.prepare_request(request) + assert prep.url == 'http://example.com/?z=1&a=1&k=1&d=1' + def test_mixed_case_scheme_acceptable(self): s = requests.Session() s.proxies = getproxies()