Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Requests.Response to be used as a context manager #4137

Merged
merged 1 commit into from Jun 7, 2017

Conversation

edmorley
Copy link
Contributor

@edmorley edmorley commented Jun 6, 2017

This saves having to wrap the call to requests with contextlib.closing(), allowing it to be used directly in a with statement, like so:

with requests.get('http://httpbin.org/get', stream=True) as r:
    # Do things with the response here.

Fixes #4136.

This saves having to wrap the call to requests with
`contextlib.closing()`, allowing it to be used directly in a
`with` statement, like so:

```
with requests.get('http://httpbin.org/get', stream=True) as r:
    # Do things with the response here.
```

Fixes psf#4136.
@Lukasa
Copy link
Member

Lukasa commented Jun 7, 2017

FYI, @kennethreitz, as you can see here the master branch is failing on the Windows builder. @requests/core for the moment we can ignore that failing Windows test and continue to merge until @kennethreitz works out what's going on with the builder. ;)

Copy link
Member

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @edmorley!

@Lukasa Lukasa merged commit 4f1b17c into psf:master Jun 7, 2017
@edmorley edmorley deleted the response-context-manager branch June 7, 2017 08:42
edmorley referenced this pull request in mozilla/treeherder Feb 12, 2019
Since `requests` has native support for being used as a context manager
as of v2.18.0:
https://github.com/kennethreitz/requests/pull/4137
edmorley referenced this pull request in mozilla/treeherder Feb 12, 2019
Since `requests` has native support for being used as a context manager
as of v2.18.0:
https://github.com/kennethreitz/requests/pull/4137
valgur added a commit to valgur/sentinelsat that referenced this pull request May 8, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants