Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch FileNotFoundError if there aren't any certificates #6749

Open
eaglegai opened this issue Jun 24, 2024 · 2 comments · May be fixed by #6750
Open

catch FileNotFoundError if there aren't any certificates #6749

eaglegai opened this issue Jun 24, 2024 · 2 comments · May be fixed by #6750

Comments

@eaglegai
Copy link

eaglegai commented Jun 24, 2024

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
Copy link
Member

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()?

@psf psf deleted a comment from Lu655 Jul 2, 2024
@eaglegai
Copy link
Author

eaglegai commented Jul 3, 2024

Hi @nateprewitt , we build a mini environment which cut off the unnecessary packages,
and in this env, we just import requests for 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants