MacOS环境下requests库报错:module 'requests' has no attribute 'SESSION'求助
Fixing
AttributeError: module 'requests' has no attribute 'SESSION' Hey there! Let's get this error sorted out quickly.
The Root Cause
This error is almost certainly a case-sensitive spelling mistake. In the requests library, the session class is named Session (only the first letter is uppercase, rest are lowercase). When you write requests.SESSION (all uppercase), Python treats this as an entirely different identifier that doesn't exist in the library—hence the "no attribute" error.
How to Fix It
- Go through your code and replace every instance of
requests.SESSIONwithrequests.Session. - Here's a quick example of how to use the session correctly:
import requests # Create a valid Session object my_session = requests.Session() # Use the session to send a request response = my_session.get("https://example.com") print(response.status_code)
Extra Checks (If the Error Persists)
- Confirm
requestsis properly installed: Runpip3 show requestsin your terminal—this should display details about the installed version. - If needed, upgrade
requests(though for Python 3.5.3, you'll get the latest compatible version):pip3 install --upgrade requests - A side note: Python 3.5.3 is no longer supported (reached end-of-life in 2020). If possible, upgrading to a newer Python version (like 3.8 or higher) will give you better security and access to newer library features.
内容的提问来源于stack exchange,提问作者hanachan1026
相关产品推荐
相关产品推荐

