Successfully resolved ImportError: cannot import name 'HTTPError' from 'urllib3.exceptions' (virtual environment running file error)

Table of contents

Problem Description

problem analysis

problem solved


Problem Description

Run the code and report an error, the error is as follows:

problem analysis

According to the error message, it can be seen that the error is the content in the urlib3 package, and the original error comes from the sentence of import request. So consider resetting the urlib3 package or reloading the request.

But the reinstallation of urlib3 failed, the reason may be: urllib is the official standard library for requesting url connections in Python, it does not need to install additional packages, it can be called directly.

ps: Of course I tried uninstalling and reinstalling, but it couldn’t be uninstalled or reinstalled. (Not sure why here)

The reason for the problem:

requests in python comes with its own copy of the urllib3 library, located in the requests/packages subdirectory. This copy was broken, so it caused an error.

problem solved

Modifying the request solved the problem

Reload the request, the code is as follows: (most effective)

pip install --force-reinstall requests==2.1.0

Although the above method is very effective in solving the problem, it is necessary to re-enter this sentence before each run . It makes me very distressed. If there is a friend who knows the solution once and for all, I hope to clear up the confusion!

Or force the request to upgrade, the code is as follows:

pip install --upgrade requests

Successful installation: no more errors

Guess you like

Origin blog.csdn.net/M_TDM/article/details/127535340