[issue42627] urllib.request.getproxies() misparses Windows registry proxy settings
狂男风 added the comment: Sorry I didn't see this comment before. Can it be merged now? -- ___ Python tracker <https://bugs.python.org/issue42627> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42627] urllib.request.getproxies() misparses Windows registry proxy settings
狂男风 added the comment: We should have no problem with how to parse HTTP proxy and HTTPS proxy. But I recently discovered an additional problem when using `requests`, that is, how to parse the SOCKS proxy correctly. I investigated the parsing of some commonly used software: `curl` will try to read the `all_proxy` variable first, if not, then read the two system environment variables `http_proxy` and `https_proxy`. Only these two environment variables related to proxy exist in most Linux distributions. The following formats are valid for `curl`: ``` export http_proxy=socks4h://127.0.0.1:5050 export https_proxy=socks5://1.1.1.1:4040 ``` The `h` in `socks4h` means doing DNS query on the proxy server. `requests` also follows this format. If you want to use the socks proxy in `requests[socks]`, you need to specify the proxies parameter: ``` proxies['http']='socks4://127.0.0.1:6060' proxies['https']='socks5h://127.0.0.1:7070' ``` Since it is customary to resolve SOCKS proxies in this way, I think CPython can consider doing the same with Windows registry. In previous versions, CPython parsed the SOCKS proxy in the Windows registry `socks=localhost:8080` as: ``` proxies['socks']='socks://localhost:8080' ``` I think it can be changed to ``` proxies['http']=proxies['http'] or'socks4://localhost:8080' proxies['https']=proxies['http'] or'socks4://localhost:8080' proxies['socks']='socks://localhost:8080' ``` The use of `or` is to prevent the existing HTTP and HTTPS proxy settings from being overwritten. I tried it on my Win10 PC. When I set up HTTP and SOCKS proxies at the same time, IE and Edge will use HTTP proxy. The reason using `socks4` instead of `socks4h` or `socks5` is that, when I change system proxy setting to a remote SOCKS proxy, I found that IE and Edge do not query DNS from the proxy but from local DNS polluted by the ISP. And if the running socks proxy version is SOCKS5, it will output errors of `unsupported socks version 0x4`. So Windows only supports the SOCKS proxy `socks4://`. It's a pity that we don't know the code of Windows, and I can't prove it with the codes. `proxies['socks']` is reserved for backward compatibility. If you have any comments or suggestions, please let me know. -- ___ Python tracker <https://bugs.python.org/issue42627> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42627] urllib.request.getproxies() misparses Windows registry proxy settings
狂男风 added the comment: I removed the multi-proxies-per-protocol support from the PR I submitted. The reason is that: 1. This code reads the proxy settings from the Windows registry. Multi-proxies-per-protocol cannot be resolved by Windows system. 2. Using a comma-separated string for the multi-proxies-per-protocol support, is not backward compatible. Not only Windows, but Linux is also one proxy per protocol. If you want to implement the multi-proxies-per-protocol support, then I think you should open another issue and make changes to all OS platforms. -- ___ Python tracker <https://bugs.python.org/issue42627> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42627] urllib.request.getproxies() misparses Windows registry proxy settings
Change by 狂男风 : -- keywords: +patch pull_requests: +24906 stage: -> patch review pull_request: https://github.com/python/cpython/pull/26307 ___ Python tracker <https://bugs.python.org/issue42627> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42627] urllib.request.getproxies() misparses Windows registry proxy settings
狂男风 added the comment: I make some black box tests with the HTTPS proxy. Set system proxy `http=https://host:port` and start a HTTPS proxy, then IE, Edge (Chromium) and benrg's code (using `urllib3`) work fine while fetching `http://website`. Then I shutdown the HTTPS proxy and start a HTTP proxy on the same port, I get SSLError. That's it. benrg should add your patch as soon as possible. Too few people actually use HTTPS proxy. Even if there is a bug with HTTPS proxy, it will not be too late to fix it when it is discovered. -- ___ Python tracker <https://bugs.python.org/issue42627> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42627] urllib.request.getproxies() misparses Windows registry proxy settings
狂男风 added the comment: We know Windows reslove: `http=host:port;https=host:port;ftp=host:port;socks=host:port` as: `http=http://host:port;https=http://host:port;ftp=http://host:port;socks=socks://host:port` means: Using HTTP type proxy for HTTP, HTTPS and FTP requests, but Socks4/4a type proxy for the other TCP requests. We notice that socks are different from the others. Now I want to know what if Windows slove this: `http=socks://host:port;ftp=https://host:port;socks=https://host:port` Does it mean using Socks4/4a type proxy for HTTP requests, HTTPS type proxy for FTP requests, and HTTP type proxy for the other TCP requests? Or just invalid settings? -- ___ Python tracker <https://bugs.python.org/issue42627> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue42627] urllib.request.getproxies() misparses Windows registry proxy settings
Change by 狂男风 : -- nosy: +CrazyBoyFeng ___ Python tracker <https://bugs.python.org/issue42627> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com