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

Add os.PathLike support for cert files #6454

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions requests/adapters.py
Expand Up @@ -276,8 +276,16 @@ def cert_verify(self, conn, url, verify, cert):

if cert:
if not isinstance(cert, basestring):
conn.cert_file = cert[0]
conn.key_file = cert[1]
# a subscriptable object
if hasattr(cert, "__getitem__"):
conn.cert_file = cert[0]
conn.key_file = cert[1]
elif hasattr(cert, "__fspath__"):
# a path-like object implements __fspath__
# see https://docs.python.org/3/library/os.html#os.PathLike
conn.cert_file = cert.__fspath__()
else:
conn.cert_file = str(cert)
else:
conn.cert_file = cert
conn.key_file = None
Expand Down