Fix pip Warning : Mirror Source is Unsafe

0, problem description

WARNING: The repository located at mirrors.tencentyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with ' --trusted-host mirrors.tencentyun.com'.

1. Solution

This problem occurs because some domestic sources and intranet sources are not configured with HTTPS. Use the following methods to ignore them. Here, Tencent Cloud intranet sources are used. If you use other sources, remember to replace the URL.

Take updating pip as an example, the original command:

Bash
1
pip3 install --upgrade pip

Temporary solution:

Bash
1
pip3 install --upgrade pip --trusted-host mirrors.tencentyun.com

Write to .bashrc:

Bash
1
2
3
echo "alias pip='pip --trusted-host mirrors.tencentyun.com'" >> ~/.bashrc
echo "alias pip3='pip3 --trusted-host mirrors.tencentyun.com'" >> ~/.bashrc
source ~/.bashrc

This is automatically ignored when executed on the command line.

Write configuration file:

In /root/.config/pip/pip.conf, the original content is:

Text
1
2
[global]
index-url = http://mirrors.tencentyun.com/pypi/simple

Change to:
[hide]

Text
1
2
3
4
5
[global]
index-url = http://mirrors.tencentyun.com/pypi/simple

[install]
trusted-host=mirrors.tencentyun.com

[hide]
Notice:
There are some weird tutorials that will teach you to use:

Bash
1
pip config set global.trusted-host mirrors.tencentyun.com

In fact, this is wrong, because the configuration item is set in the wrong place, so be careful not to be misled.

Fix pip Warning : Mirror Source is Unsafe

https://blog.tsinbei.com/en/archives/739/

Author
Hsukqi Lee
Posted on

2023-06-22

Edited on

2023-06-22

Licensed under

CC BY-NC-ND 4.0

Comments

Name
Mail
Site
None yet