Commit Graph

286 Commits

Author SHA1 Message Date
Cory Benfield 0838685dab Replace tab with appropriate spaces. 2016-05-12 10:57:52 +01: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
liuyang 2981366f56 add rtype in session.request 2016-04-11 14:33:23 +08: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
kennethreitz fc512d8924 Don't use redirect_cache if allow_redirects=False
Fix for #2997
2016-02-05 17:51:09 -05:00
Ryan Munro 6a8a480d6c Review changes to TooManyRedirect exception with response 2016-01-20 10:48:12 -08:00
Ryan Munro e6f218f3f6 Return request & response with TooManyRedirects 2016-01-19 16:44:58 -08:00
Brian Samek 9aca57d4bf Revert changes to params
This reverts commit 9a20afd6b5.

Docstring changes were desirable, but changes to params were not.
2015-12-11 16:47:47 -05:00
Brian Samek 9a20afd6b5 Refactor default params
Specified the default argument for params that have a default in the docstring
so that the default is easier to see from the code. Modified the docstring in
api.py to match the docstring in sessions.py.
2015-12-11 13:32:09 -05:00
Brian Samek 3ad66349ea Add hint to :param verify.
It is not clear that :param verify defaults to True. The way the verify
portion of the docstring is written it looks like it defaults to False, and
you have to pass in True if you'd like the SSL cert to be verified, but the
opposite is the case.
2015-12-09 11:21:21 -05:00
Jakub Wilk 23d9b077d8 Fix typos 2015-12-01 12:24:56 +01:00
Daniel Müller d8f28f4bca Fixed usage example in sessions.py 2015-10-15 14:32:35 +02:00
Cory Benfield 2df3c7c75d Move to_native_string for methods to prepare() 2015-10-12 10:50:37 +01:00
Doctor-love 63b3b9be55 Clarified description for option "trust_env" 2015-10-02 14:47:50 +02:00
Cory Benfield 56ecdebcc5 Merge pull request #2741 from jasongrout/per-host-proxy
Implement per-host proxies
2015-09-06 15:02:40 +12:00
Jason Grout 2c8721540a Fix documentation for proxies in the Session class 2015-08-27 17:26:45 +00:00
Everett Toews 8b03cd96cb Include file-like object in data arg description 2015-08-24 18:28:41 -05:00
Martijn Pieters 4947cd01ae Avoid altering dictionary size during iteration, by gathering keys that need to be deleted first.
Fixes `RuntimeError` on Python 3 introduced in 53ea23128e
2015-08-21 08:44:09 +01:00
Ian Cordasco 53ea23128e Merge pull request #2706 from ak1r4/fix-merge-setting
Fix merge setting for not preserving original order of dict parameters
2015-08-15 10:39:46 -05:00
Lukas Graf f40bd0f707 Docs: Fix links to timeouts section by using :ref: instead of
linking to .html files.
2015-08-15 12:03:05 +02:00
Lukas Graf 75c1776bde Document use of sessions as context managers. 2015-08-07 20:48:03 +02:00
Akira J 276202f51e Fix merge setting for not preserving original order of dict parameters 2015-08-04 22:47:12 +01:00
Paul van der Linden 587eb193dd fix resolve redirect to pass all original arguments 2015-03-26 19:57:16 +00:00
Cory Benfield f7c85685a8 Add explanatory comment for cookie change 2015-03-14 11:29:05 +00:00
Cory Benfield 3bd8afbff2 Don't ascribe cookies to the target domain. 2015-03-14 08:49:55 +00:00
kennethreitz 53d02381e2 Merge pull request #2349 from sigmavirus24/fix-pickling
Properly serialize RecentlyUsedContainers for cache
2014-11-30 14:12:43 -05:00
Matt Robenolt 2a5364cf72 url was already parsed, don't urlparse twice 2014-11-23 17:54:44 -08:00
Ian Cordasco c8baf88125 Properly serialize RecentlyUsedContainers for cache
RecentlyUsedContainers are threadsafe so they require a lock and as such
cannot be serialized with pickle directly. To handle it, we need to
convert it to a dictionary first and then back when deserializing.

Fixes #2345
2014-11-17 22:16:32 -06:00
Ian Cordasco 431282e778 Merge pull request #2299 from mattrobenolt/master
Cap the redirect_cache size to prevent memory abuse
2014-11-07 14:18:41 -06:00
Ian Cordasco 29ef108158 Use to_native_string instead of builtin_str
Fixes #2316
2014-10-31 21:20:04 -05:00
Matt Robenolt 387c8f852c Cap the redirect_cache size to prevent memory abuse 2014-10-27 09:20:06 -07:00
Ian Cordasco 0e4efab270 Re-order params for backwards compat 2014-10-05 18:55:59 -05:00
kennethreitz 1e79cf6a47 Merge pull request #2258 from willingc/add-json
Add json parameter
2014-10-05 12:46:09 -04:00
Ian Cordasco b1f3a2dd66 Remove timeout from __attrs__
We do not allow the user to set the timeout value on the Session any longer so
this is extraneous
2014-10-04 23:04:36 -05:00
Ian Cordasco 8ed941fa69 Fix a couple of issues I noticed
- Don't _ prefix json in prepare_body
- Don't initialize json to []
- Don't initialize json to {}
- Reorder parameters to PreparedRequest.prepare
- Remove extra parentheses
- Update docstring
2014-09-30 16:03:31 -05:00
Ian Cordasco ac44b48297 Avoid getting stuck in a loop
This prevents a case where we make a request to URL A, which 301s to B which
would then 301 back to A. Alternatively, for less simple schemes, this will
also prevent us from getting stuck in a loop, e.g., it will prevent the
following from causing an endless loop:

    A -> B -> C -> D -> E -> F --
    ^                             \
    |                             /
    ---<------------<----------<-
2014-09-22 21:01:36 -05:00
Ian Cordasco 27c83f7177 Fix #2207
@Lukasa wrote the fix in #2207
2014-09-07 12:02:23 -05:00
Kevin Burke dfa41afd43 Document Timeout behaviour 2014-08-29 11:50:11 -07:00
Carol Willing 8f17741849 Adds json parameter for POST requests 2014-08-28 12:53:19 -07:00
Ian Cordasco 596ca83f0c Update verify check and doc-string 2014-08-26 14:20:19 -05:00
Ian Cordasco b4a7906bca Add Session method to merge environment settings with per-request settings 2014-08-26 14:20:19 -05:00
ContinuousFunction c7e087cf56 Added space and sentence case
Added space and sentence case as requested by sigmavirus24.
https://github.com/kennethreitz/requests/pull/2168
2014-08-21 11:05:02 -07:00
ContinuousFunction 2fc6e8a894 Update on Tracking Previous Requests
Modified the comment in sessions.py and rewrote the test in
test_requests.py
2014-08-19 10:51:26 -07:00
ContinuousFunction df641e74ff Tracking Previous Requests
Addresses the issue brought up here:
https://github.com/kennethreitz/requests/issues/1929
2014-08-17 19:13:26 -07:00
Ian Cordasco 3957b0befb Fix silly check 2014-07-02 10:42:00 -05:00
Ian Cordasco 84f67379c8 Update how we check verify when inspecting env variables 2014-07-02 10:26:15 -05:00
Eric L Frederich c3444f8c7a don't make duplicate requests for permanent redirects 2014-06-12 08:25:21 -04:00
Eric L Frederich ec3a2e6f04 rename resume/resume_incomplete to permanent_redirect according to rfc7238
Use temporary_redirect intead of temporary_moved to make the words
line up nicely ;-)
2014-06-11 11:08:10 -04:00
Cory Benfield 22433163b3 Update trivial mentions to RFC 2616. 2014-06-07 09:53:12 +01:00
schlamar 59c8d81381 Read content in Session.send instead of Adapter.send. 2014-05-12 22:42:54 +02:00