Skip to content

implement requests.Response context manager to use in with statement #1072

@rgl

Description

@rgl

In MicroPython 1.27.0 we can make a HTTP request like:

import requests
r = requests.get("http://ip6.me/api/", timeout=15)
print(r.text)
r.close()

Unfortunately, we cannot simplify that code to use the with statement:

with requests.get("http://ip6.me/api/", timeout=15) as r:
  print(r.text)

Because it fails with:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Response' object has no attribute '__exit__'

Can that be implemented?

PS: Oh there is a PR at #278 that seems to implement this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions