requests icon indicating copy to clipboard operation
requests copied to clipboard

proxies argument option: handles bytes literals in dict differently from other argument options

Open Sekin opened this issue 7 years ago • 3 comments

https_proxy = b'http://localhost:8080'
http_proxy = b'http://localhost:8080'
proxy_dict = {b'https' : https_proxy, b'http' : http_proxy}

r = requests.request(url, proxies=proxy_dict, verify=False)

Expected Result

The proxies argument option accepts bytes literals as arguments, and proxies are being used.

Actual Result

The proxies argument option accepts bytes literals as arguments, but seems to disregard them internally: Proxies have no effect. However, no exception is raised either.

Problem

The proxies argument option handles bytes literals differently compared to the other argument options, e.g.. parameters or data. The proxies argument option only works with str:

https_proxy = 'http://localhost:8080'
http_proxy = 'http://localhost:8080'
proxy_dict = {'https' : https_proxy, 'http' : http_proxy}

Exceptions are ignored. Using bytes literals does not raise an exception.

Sekin avatar Jul 03 '19 14:07 Sekin

Going to check this out

DougCal avatar Jun 29 '20 14:06 DougCal

I think we need to establish why byte literals should be accepted. I don't believe you can pass a bytes literal as a URL to requests.

sigmavirus24 avatar Jun 29 '20 15:06 sigmavirus24

This ended up getting answered but this issue wasn't closed. proxies arguments must be a str based dict for both keys and values. URLs that are bytes have a number of undefined behaviors within the Requests codebase. We normalize all url input directly into Requests to strings and that's the assumption the internals of the library operate on.

nateprewitt avatar Mar 30 '26 02:03 nateprewitt