Azure / Azure/azure-cli

Usages of `urllib.request.urlopen` should be replaced by `requests`

Open
#26,008 11 comments 1 reaction 1 assignee Claimed by @jiasli View on GitHub
act-platform-engineering-squad Azure CLI Team Core question
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.