psf / psf/requests

chunk size error for unicode content

Open
#2,235 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Breaking API Change Planned
Dominant language
Python
Stars
54.3k
Forks
10.4k
Avg merge
16h 43m
Merged PRs (30d)
3

Description

I found this code in requests/adapters.py (latest version installed by pip):

https://github.com/kennethreitz/requests/blob/master/requests/adapters.py#L383

for i in request.body:                                                     
       low_conn.send(hex(len(i))[2:].encode('utf-8'))

if i is a unicode, the low_conn send utf8 encoding byte string, but the chunk size is wrong.
I think it should change to:

if isinstance(i, unicode):
  i = i.encode('utf8')
low_conn.send(hex(len(i))[2:].encode('utf-8'))

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 in requests/adapters.py at the chunk-sending loop referenced in the issue. Reproduce the behavior with unicode request content and verify that the emitted chunk size matches the UTF-8 byte content; done when the mismatch is corrected and the relevant behavior is covered by verification.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.