micropython / micropython/micropython-lib
requests: requests.get() blocks infinitely
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 1.1k
- Avg merge
- 7d 6h
- Merged PRs (30d)
- 3
Description
I am trying to call requests.get(some_REST_API_call) on a Pico W (with v1.22.1) but this call blocks infinitely.
Using a timeout or non-blocking mode (timeout=0) doesn't help.
The call works with CPython and in Chrome and returns some small JSON.
When using self._cached = self.raw.recv(10000) instead of self._cached = self.raw.read()
in requests/__init__.py (line 20) the call works fine.
So shouldn't this read() be replaced with a loop which tries to recv(num_bytes)
until it read less than num_bytes and then stops?
Update: Tested this with a different kind of device (calling the ThingSpeak API with requests.post) and for that only read() works correctly. recv(num_bytes) yields no bytes.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with requests/init.py around line 20 and reproduce the Pico W requests.get and requests.post cases described. Compare the blocking behavior and returned data from raw.read() and raw.recv(10000), including timeout=0. Done means the affected calls complete without hanging while preserving the response behavior that currently works for each device.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100