解決urllib3 (1.26.1) or chardet (3.0.4) doesn’t match a supported version問題

前言

在Python 3.8版本底下使用requests套件時,遇到如文章標題的警告訊息,雖然不是錯誤訊息,但是每次執行程式都會跳出這樣的訊息出來也是蠻煩人,因此在這篇文章中記錄該如何解決這個警告的問題。

警告訊息

在執行Python程式的時候,會出現下列的警告訊息:


$ python download_pcc.py
F:\python-3.8.10win32\lib\site-packages\requests\__init__.py:102: RequestsDependencyWarning: urllib3 (1.26.9) or chardet (5.1.0)/charset_normalizer (2.0.12) doesn't match a supported version!
warnings.warn("urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported "

看起來是套件版本的問題,因為requests與urllib3是相依的關係,因此需要透過升級套件的版本來解決這個警告訊息,這時可以透過pip指令來解決這個問題:


pip install -U urllib3 requests
Requirement already satisfied: urllib3 in f:\python-3.8.10win32\lib\site-packages (1.26.9)
Collecting urllib3
Downloading urllib3-2.2.1-py3-none-any.whl (121 kB)
|████████████████████████████████| 121 kB 344 kB/s
Requirement already satisfied: requests in f:\python-3.8.10win32\lib\site-packages (2.27.1)
Collecting requests
Downloading requests-2.31.0-py3-none-any.whl (62 kB)
|████████████████████████████████| 62 kB 573 kB/s
Requirement already satisfied: idna<4,>=2.5 in f:\python-3.8.10win32\lib\site-packages (from requests) (3.3)
Requirement already satisfied: certifi>=2017.4.17 in f:\python-3.8.10win32\lib\site-packages (from requests) (2021.10.8)
Requirement already satisfied: charset-normalizer<4,>=2 in f:\python-3.8.10win32\lib\site-packages (from requests) (2.0.12)
Installing collected packages: urllib3, requests
Attempting uninstall: urllib3
Found existing installation: urllib3 1.26.9
Uninstalling urllib3-1.26.9:
Successfully uninstalled urllib3-1.26.9
Attempting uninstall: requests
Found existing installation: requests 2.27.1
Uninstalling requests-2.27.1:
Successfully uninstalled requests-2.27.1
Successfully installed requests-2.31.0 urllib3-2.2.1

這樣一來就不會出現這個警告訊息了。

參考資料