micropython / micropython/micropython-lib

urequests: TypeError: object with buffer protocol required

Open
#553 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
1.1k
Avg merge
7d 6h
Merged PRs (30d)
3

Description

r=urequest.post("http://www.example.com",headers={"Content-Length":19},data='{"hello":"world"}')
print(r.status_code,r.content)

Seems that that 19 is the issue and it needs to be a string, should the user of the lib be expected to know this or should this:

        for k in headers:
            s.write(k)
            s.write(b": ")
            s.write(headers[k])
            s.write(b"\r\n")

be changed to this:

        for k in headers:
            s.write(k)
            s.write(b": ")
            s.write(str(headers[k]))
            s.write(b"\r\n")

on a side note, why does this not happen with header={}
https://forums.raspberrypi.com/viewtopic.php?t=341355

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the posted request in python-ecosys/urequests/urequests.py, then read the header-writing loop around line 101 and compare how integer and string header values reach s.write(). Done means the expected handling of Content-Length=19 is established and the related header behavior is covered by the project’s available checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.