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

HttpHeaderDict does not support bytes object #3072

Open
tushar5526 opened this issue Jun 17, 2023 · 4 comments · May be fixed by #3279
Open

HttpHeaderDict does not support bytes object #3072

tushar5526 opened this issue Jun 17, 2023 · 4 comments · May be fixed by #3279
Labels
💰 Bounty $100 If you complete this issue we'll pay you $100 on OpenCollective!

Comments

@tushar5526
Copy link
Contributor

Subject

Passing bytes as the value in HttpHeaderDict is not handled completely.

Environment

Describe your environment.
At least, paste here the output of:

import platform
import ssl
import urllib3

print("OS", platform.platform())
print("Python", platform.python_version())
print(ssl.OPENSSL_VERSION)
print("urllib3", urllib3.__version__)
OS Linux-5.19.0-43-generic-x86_64-with-glibc2.35
Python 3.10.6
OpenSSL 3.0.2 15 Mar 2022

Steps to Reproduce

import urllib3

headers = urllib3.HTTPHeaderDict()
encoded_data = "Schönefeld/1.18.0".encode('latin-1')

headers['user-agent'] = encoded_data
headers['user-agent']
print(headers['user-agent'])

Expected Behavior

You can access bytes objects passed in headers.

Actual Behavior

Errors out with this

Traceback (most recent call last):
  File "/home/tushar55/test.py", line 8, in <module>
    headers['user-agent']
  File "/home/tushar55/projects/urllib3/src/urllib3/_collections.py", line 260, in __getitem__
    return ", ".join(val[1:])
TypeError: sequence item 0: expected str instance, bytes found

Bytes are not handled - https://github.com/urllib3/urllib3/blob/main/src/urllib3/_collections.py#L257 , https://github.com/urllib3/urllib3/blob/main/src/urllib3/_collections.py#L426

Using bytes as keys has some level of handling - https://github.com/urllib3/urllib3/blob/main/src/urllib3/_collections.py#L251

Found this issue while going through #3047

@panzer
Copy link

panzer commented Sep 6, 2023

@tushar5526 Are you looking for someone to contribute a fix? If so, I can look into it.

@tushar5526
Copy link
Contributor Author

Hi @ panzer, this issue is still not confirmed. The core maintainers have not triaged this one yet. Let's wait for them :)

@panzer
Copy link

panzer commented Sep 13, 2023

@tushar5526 I'm looking through some old issues and pull requests. It seems the maintainers do not do much triage. I'm willing to look work on this issue. If we want to wait for a maintainer to review, let's get in touch directly with that person

@sethmlarson
Copy link
Member

@tushar5526 @panzer Thanks for the patience, it would be great to have support for bytes as values in HTTPHeaderDict. I'm not sure how exactly that would work internally, maybe you have some ideas :)

@sethmlarson sethmlarson added the 💰 Bounty $100 If you complete this issue we'll pay you $100 on OpenCollective! label Jan 9, 2024
@zawan-ila zawan-ila linked a pull request Jan 14, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💰 Bounty $100 If you complete this issue we'll pay you $100 on OpenCollective!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants