我的python请求代理密码有hashtag“#”,它无法解析代理URL

i2loujxw  于 2023-08-02  发布在  Python
关注(0)|答案(1)|浏览(101)

我的代理是:'http://abc:zyx#123$@http://proxy. mycompany. com:8800/';
当我跑步时:

response = requests.get(
            url, stream=True, headers=headers, proxies=my_proxies);

字符串
我得到了错误:
文件“C:\Program Files\Python\310\lib\site-packages\requests\api.py ",line 115,in post return request(" post ",url,data = data,json = json,**kwargs)File" C:\Program Files\Python\310\lib\site-packages\requests\api.py ",第59行,在请求返回会话中。request(method = method,url = url,**kwargs)File" C:\Program Files\Python\310\lib\site-packages\requests\sessions.py ",第589行,在request resp = self中。send(prep,**send_kwargs)文件" C:\Program Files\Python\310\lib\site-packages\requests\sessions.py",第703行,在send r = adapter中。send(request,**kwargs)文件" C:\Program Files\Python\310\lib\site-packages\requests\adapters.py",第456行,在send中引发InvalidURL(e,request = request)请求。例外情况。InvalidURL:解析失败:http://abc:zyx#123$@http://www.example.com
当我从密码中删除#时,我得到了以下错误:文件“C:\Program Files\Python\310\lib\site-packages\requests\api.py ",line 115,in post return request(" post ",url,data = data,json = json,**kwargs)File" C:\Program Files\Python\310\lib\site-packages\requests\api.py ",第59行,在请求返回会话中。request(method = method,url = url,**kwargs)File" C:\Program Files\Python\310\lib\site-packages\requests\sessions.py ",第589行,在request resp = self中。send(prep,**send_kwargs)文件" C:\Program Files\Python\310\lib\site-packages\requests\sessions.py",第703行,在send r = adapter中。send(request,**kwargs)文件" C:\Program Files\Python\310\lib\site-packages\requests\adapters.py",第513行,在send中引发ProxyError(e,request = request)请求。例外情况。代理错误:HTTPSConnectionPool(host ='api.precisely.com',port = 443):URL超过最大重试次数:/oauth/token(Caused by ProxyError('Unable to connect to proxy',NameResolutionError(":Failed to resolve 'http'([Errno 11001] getaddrinfo failed)"))按任意键继续。<urllib3.connection.HTTPSConnection object at 0x00000202D2877190>……
我认为是密码中的#导致了错误,我该如何解决?

aurhwmvo

aurhwmvo1#

根据RFC 3986,userinfo部分需要进行pct编码:
userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
这应该可以工作:

my_proxies = {"http": "http://abc:zyx%23123%24@proxy.mycompany.com:8800/"}

response = requests.get(url, proxies=my_proxies)

字符串
因为#$的百分比编码形式分别是%23%24

相关问题