psf / requests

A simple, yet elegant, HTTP library.
https://requests.readthedocs.io/en/latest/
Apache License 2.0
52.2k stars 9.34k forks source link

catch FileNotFoundError if there aren't any certificates #6749

Open eaglegai opened 5 months ago

eaglegai commented 5 months ago

I set verify to False, but it still need cerfiticate. As we have catched ImportError, why not catch FileNotFoundError together?

Expected Result

won't Traceback

Actual Result

[root@localhost requests]# ./test-requests.py
Traceback (most recent call last):
  File "/root/test/requests/./test-requests.py", line 2, in <module>
    import requests
  File "/usr/lib/python3.9/site-packages/requests/__init__.py", line 136, in <module>
    from .api import request, get, head, post, patch, put, delete, options
  File "/usr/lib/python3.9/site-packages/requests/api.py", line 13, in <module>
    from . import sessions
  File "/usr/lib/python3.9/site-packages/requests/sessions.py", line 28, in <module>
    from .adapters import HTTPAdapter
  File "/usr/lib/python3.9/site-packages/requests/adapters.py", line 65, in <module>
    _preloaded_ssl_context.load_verify_locations(
FileNotFoundError: [Errno 2] No such file or directory

Reproduction Steps

#!/usr/bin/python3
import requests
r = requests.get("http://127.0.0.1",verify=False)
print(r.text)
nateprewitt commented 4 months ago

Hi @eaglegai, certifi is a declared dependency of Requests. This should be available in all installations. We derive the the DEFAULT_CA_BUNDLE_PATH being used in this line from requests.certs.where().

Can you confirm you 1.) have certifi installed and 2.) the value of import requests; requests.certs.where()?

eaglegai commented 4 months ago

Hi @nateprewitt , we build a mini environment which cut off the unnecessary packages, and in this env, we just import requestsfor http:// and verify is false is enough. It's not reasonable to force to load the certificates by default, because it's not necessary in the case that verify is false.

As we consider the case that isn't built with the ssl module, why not consider the situation that 'verify is false' needn't certificates.