pip安装selenium遇Tunnel connection failed:403 Forbidden错误求助
Hey there, let's get this pip installation issue sorted out! That 403 Forbidden error means your pip request is getting blocked by a proxy server—either the system proxy you're using doesn't have permission to access PyPI, or pip is picking up a proxy setting that's not working correctly.
Here are some straightforward fixes you can try, in order of simplicity:
1. Install Without Proxy (Quick Test)
First, try telling pip to skip using any proxy entirely with this command:
pip install selenium --no-proxy
This is the fastest way to confirm if the proxy is the root cause.
2. Clear System Proxy Environment Variables
Sometimes your Windows system has proxy variables set that pip automatically uses. Let's check and clear them temporarily:
- Open your command prompt and run these to see if proxies are configured:
echo %HTTP_PROXY% echo %HTTPS_PROXY% - If you see proxy URLs returned, clear them with:
set HTTP_PROXY= set HTTPS_PROXY= - Now try installing selenium again with the original command:
pip install selenium
3. Use a Domestic PyPI Mirror (Most Reliable for China Users)
If the issue is accessing the official PyPI server, switching to a domestic mirror will bypass the proxy problem entirely:
- Temporary use (run this directly):
pip install selenium -i https://pypi.tuna.tsinghua.edu.cn/simple - To set it permanently (so you don't need to add the
-iflag every time):- Go to your user folder (e.g.,
C:\Users\YourUsername) - Create a folder named
pip - Inside that folder, create a file named
pip.iniwith this content:[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple - Save the file, and future pip installs will use this mirror by default.
- Go to your user folder (e.g.,
4. Configure Correct Proxy Settings (If You Need Proxy Access)
If you must use a proxy to access the internet, make sure you have the right credentials and settings:
Run this command, replacing the placeholders with your actual proxy details:
pip install selenium --proxy=http://your-username:your-password@proxy-address:proxy-port
Your Original Error Details
For reference, here's the error you encountered:
(base) C:\>pip install selenium Collecting selenium Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden'))': /packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden'))': /packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden'))': /packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden'))': /packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden'))': /packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))
内容的提问来源于stack exchange,提问作者Monkeydave




