Commit Graph

114 Commits

Author SHA1 Message Date
messense cb4c2c0b65 Fix TypeError when get json-encoded content of a response
``self.content`` could be ``None``, so ``len(self.content)`` may raise ``TypeError: object of type 'NoneType' has no len()``
2016-05-06 09:53:14 +08:00
kennethreitz ce5e312593 Merge pull request #3096 from piotrjurkiewicz/master
Change _store of CaseInsensitiveDict to OrderedDict
2016-04-29 17:47:35 -04:00
Kevin Burke ae1ac2d4e0 Flip conditional in session.send()
Previously we checked that the `request` being sent was an instance of a
PreparedRequest. If a user somehow created a PreparedRequest using a different
Requests library instance, this check makes the request un-sendable.

(This happened recently - unbeknownst to me, my server was running an outdated
version of pip, vulnerable to this issue - pypa/pip#1489, which creates
multiple subdirectories (src/requests, src/requests/requests) when you rerun
pip install --target. So the PreparedRequest was being created in one version
of the library and compared against the other version of the library, and
throwing this exception, even though they were both PreparedRequest instances!)

It would probably be preferable to check the object's behavior (instead of
its type), but a PreparedRequest has a lot of behavior, and it wouldn't be
really feasible or allow us to provide a helpful error message to check all
of it here. Instead flip the conditional to guard against the user sending an
unprepared Request, which should still give us most of the benefits of the
better error message.

Fixes #3102
2016-04-21 08:12:05 -07:00
Piotr Jurkiewicz b1a7dcd799 Fix test_headers_preserve_order 2016-04-16 22:21:10 +02:00
Matt Dainty 2029a8a931 Clear any pooled proxy connections
As well as clearing any pooled direct connections, iterate over any
ProxyManager objects and clear any pooled proxy connections there as well.
2016-04-15 09:33:37 +01:00
Piotr Jurkiewicz c8a0fc6aa2 Use OrderedDict from .compat module 2016-04-15 04:43:53 +02:00
Piotr Jurkiewicz 4f5741e1ff Add test of headers order preservation 2016-04-15 00:35:57 +02:00
tzickel 219490ea7f Make a dummy test 2016-04-08 23:17:37 +03:00
tzickel 2246a52a36 Added a test to show a faulty behaviour when posting binary data for an object
with no __iter__
2016-04-08 20:25:01 +03:00
kennethreitz 03ed671a41 Merge pull request #3059 from alexanderad/proxy-connection-errors
Raise a ProxyError for proxy related connection issues
2016-04-06 15:01:25 -04:00
Ben f24d56a1ce Consolidate logic for changing method during redirects
I only moved the code into a function, there was no actual change to
the code. I added a few tests to ensure we're doing things correctly.

The real point of me doing this is to make it easier to bring back
`strict_mode` functionality. For you requests youngsters in the crowd,
`strict_mode` followed the spec for redirects meaning the method
wouldn't change to a GET. The current code follows the browser
convention of changing the method to a GET when doing a 302 redirect.
However, lots of servers want you to follow the standards (the nerve!)
so I'd like to override the logic. Now that the method changing logic
is in `rebuild_method`, I can simply override that function instead of
overriding the entire `resolve_redirects` function as suggested by
kennethreitz/requests#1325
2016-03-17 23:16:39 -05:00
Alexander Shchapov 6ca9d71bb5 Raise a ProxyError for proxy related connection issues. 2016-03-17 15:46:26 -04:00
Casey Davidson f74a6707af Verify that cookie can be properly accessed if domain is specified, and that error is raised otherwise. Refs #3028. 2016-03-05 20:37:56 -08:00
Casey Davidson c53a685e7d Fix typo. 2016-03-05 20:30:36 -08:00
Casey Davidson b9517a58bc Assert that both cookies were added in test. Refs #3028. 2016-03-04 15:59:13 -08:00
Casey Davidson 1185d65202 Add tests to specify when CookieConflicError should be raised. References #3028. 2016-03-04 15:55:43 -08:00
kennethreitz bbadf47a8f syntax changes 2016-02-05 15:53:59 -05:00
Dmitry Dygalo 18b26d20f7 Added tests module. 2016-02-05 13:21:57 +01:00
Kenneth Reitz e4c4c80b82 remove all old tests 2012-12-17 07:27:25 -05:00
Kenneth Reitz 79992579c9 remove danger_mode tests 2012-12-14 23:27:38 -05:00
Kenneth Reitz 67c7e496f5 remove safe_mode tests 2012-12-14 23:26:48 -05:00
Kenneth Reitz d36ceb9d06 Merge pull request #953 from heyman/fix_session_safe_mode
Fixes so that safe_mode works for Sessions
2012-11-26 00:31:45 -08:00
Cory Benfield d5f9a2a51c Avoid using callable().
Callable() is not included in Python 3.1, so we shouldn't use it.
2012-11-24 12:15:30 +00:00
Jonatan Heyman 8269ee7266 Fixed so that safe_mode works for Sessions 2012-11-23 16:48:51 +01:00
Russell Davis ccf4ca8929 Fix a bug in _encode_params - it wasn't utf-8 encoding strings in values that
are iterable but not a list.
2012-11-03 12:58:04 -07:00
Radu Voicilas ce7c86cc58 Replace assert statements with unittest's self.assert*
-- the incetive for this being that with self.assertEqual you get an
error message if the test fails
2012-10-18 22:24:59 +03:00
Kenneth Reitz aa08f33f98 Merge pull request #884 from everbird/develop
Support CJK parameters when post files
2012-10-17 07:21:39 -07:00
Stephen Zhuang bb9e72885a For the uniformity :) 2012-10-09 23:19:42 +08:00
Radu Voicilas 820dfb0495 Making the code more PEP8 compliant 2012-10-09 00:42:49 +03:00
Ian Cordasco 4e6cf21d82 Only register callable items in lists
Prior to this, you could sneak a list of anything to register_hook and it
would accept it. This will check if the items in the list are callable before
registering them. Also added a regression test to make sure if this gets
changed it will be noticed.
2012-10-09 00:42:49 +03:00
Stephen Zhuang 86b39bf3e3 Support CJK parameters when post files 2012-10-08 16:52:06 +08:00
Ian Cordasco 77677eb71d Only register callable items in lists
Prior to this, you could sneak a list of anything to register_hook and it
would accept it. This will check if the items in the list are callable before
registering them. Also added a regression test to make sure if this gets
changed it will be noticed.
2012-10-01 14:05:27 -04:00
Ian Cordasco 4dd3d1a1a2 Fix #785 & add regression test. 2012-09-20 11:45:03 -04:00
Shivaram Lingamneni c73646da00 fix some tests to correctly cover the API
After #831, the tests added in #764 (which relied on iter_content()
crashing if the response was prefetched) no longer tested what they
were intended to test.
2012-09-06 16:31:01 -07:00
Shivaram Lingamneni 77cf995165 permissive implementation of iter_content
This allows iter_content and iter_lines to succeed without
crashing even after the response content has been fetched
(iter_content gives you an iterator over the prefetched
content)
2012-09-02 01:42:30 -07:00
Kenneth Reitz 088454b145 Merge pull request #805 from Lukasa/develop
Remove None values from post data.
2012-08-25 07:35:06 -07:00
Rhys Elsmore 217a9d50cd Removed Duplicate Import 2012-08-23 16:18:47 +10:00
Cory Benfield b781acc7ab Add a failing test for Issue #378. 2012-08-22 22:33:20 +01:00
Kenneth Reitz 385217e55c Merge pull request #789 from zigmonty/http_digest_fixes
HTTPDigestAuth fixes
2012-08-18 17:42:40 -07:00
Ian Cordasco a5d462e176 Revert "Some pyflakes fixes."
This reverts commit c71f48b5f1.

To please his BDFLness @kennethreitz ;)
2012-08-18 18:31:58 -04:00
Ian Cordasco ab56e4a9f1 Fix python3 tests.
I wasn't thorough enough with how I dealt with headers. Most of the header
logic in the Request object utilizes dictionary properties which will not work
with a key/value list.

I'll dig more into this, but I know the rest of the features are more
important so I'll take my time on this and send a separate pull request.
2012-08-18 14:41:13 -04:00
Ian Cordasco f01694e274 All tests pass, time for a PR. 2012-08-18 13:47:14 -04:00
Ian Cordasco e02da89337 Merge branch 'develop' into key_val_lists
Conflicts:
	requests/models.py
	tests/test_requests.py

Remove some of Lukasa's duplication of my efforts in _encode_data.
2012-08-18 12:15:03 -04:00
Peter Montagner 6d02036092 Extend digests test case to connect twice using the same auth and confirm the second one went direct. 2012-08-18 15:33:05 +10:00
Locker537 42d0a2169e Whitespace fixes following PEP8. 2012-08-16 17:38:35 -04:00
Cory Benfield e08b853a0c Test for throwing useful exception on bad label. 2012-08-13 21:18:56 +01:00
Jakub Roztocil 88c762e256 Fixed tests for Python 3 (text vs. bytes). 2012-08-11 08:19:35 +02:00
Jakub Roztocil dee3693ea0 Use BytesIO for bytes.
This fixes a TypeError on Python 3 that ocurred when passing
bytes as the values for files.
2012-08-10 19:49:03 +02:00
Jakub Roztocil cfa627ae62 Fixed encoding of fields with the same name.
* Properly handle repeated data fields for multipart/form-data requests (#737)
* Allow a list of 2-tuples as the `files` agument.
* Consistently serialize lists a of parameters (#729).
2012-08-10 19:49:03 +02:00
Kenneth Reitz a65e8b4a22 Merge pull request #767 from stefanp/develop
Wrap socket.error in ConnectionError (+ unit tests)
2012-08-08 13:23:10 -07:00