Usages of `urllib.request.urlopen` should be replaced by `requests`
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 3.5k
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 60
Description
When verifying HTTPS connection, `urlopen` and `requests` by default use different CA bundles:
- `urlopen` uses the system CA bundle (https://docs.python.org/3/library/ssl.html#ssl.create_default_context)
- `requests` uses (https://requests.readthedocs.io/en/latest/user/advanced/#ssl-cert-verification)
1. `REQUESTS_CA_BUNDLE`
2. `CURL_CA_BUNDLE`
3. `certifi.where()`
Such inconsistency frequently causes issues. It is also difficult to handle such inconsistency correctly:
- https://github.com/Azure/azure-cli/pull/20183
- https://github.com/Azure/azure-cli/pull/21807
- https://github.com/Azure/azure-cli/issues/26007
According to the documentation of `urllib.request`:
https://docs.python.org/3/library/urllib.request.html
> The [Requests package](https://requests.readthedocs.io/en/master/) is recommended for a higher-level HTTP client interface.
All Azure Python SDKs use `requests` to make HTTPS request, so does `azure.cli.core.util.send_raw_request`, so all usages of `urllib.request.urlopen` should be replaced by `requests`.
Contributor guide
Assessment
This issue has not been assessed yet.