Heroku部署Python应用报错:无法导入InsecureRequestWarning
Let's break down what's happening and how to resolve this issue quickly:
Root Cause
This error comes down to incompatible dependency versions—specifically with requests and urllib3. Python 3.6.4 is end-of-life (EOL), meaning newer releases of these libraries have dropped support for it. Even though you only modified your README.md, Heroku’s build process reinstalls dependencies during deployment. If your Pipfile/Pipfile.lock didn’t pin compatible versions, Heroku pulled in updated library versions that break the InsecureRequestWarning import.
Step-by-Step Fix
Pin compatible dependency versions locally
Run these commands in your project directory to install the last versions ofrequestsandurllib3that officially support Python 3.6.4:pipenv install requests==2.27.1 urllib3==1.26.15Update your lock file
Generate an updatedPipfile.lockto guarantee Heroku installs exactly these compatible versions:pipenv lockCommit and redeploy
Add the updatedPipfileandPipfile.lockto your testing branch, commit the changes, and push to Heroku again:git add Pipfile Pipfile.lock git commit -m "Pin requests/urllib3 versions for Python 3.6 compatibility" git push heroku testing:master
Long-Term Recommendation
Python 3.6 reached end-of-life in December 2021, so it no longer receives security updates or library support. For long-term stability and security, plan to upgrade your application to a supported Python version (e.g., 3.8 or newer). This will eliminate dependency compatibility issues like this in the future.
内容的提问来源于stack exchange,提问作者Benjamin Dobell

