`cert` parameter does not accept a single `pathlib.Path` object as argument
Open
Nobody has claimed this yet.
Feature Request
- Dominant language
- Python
- Stars
- 54.3k
- Forks
- 10.4k
- Avg merge
- 16h 43m
- Merged PRs (30d)
- 3
Description
requests seems to have special handling for when the cert parameter is a single str, but does not extend the same special handling to pathlib.Path, meaning currently you either have to do cert=str(path) or cert=(path, path).
Expected Result
Path objects should be handled just like str.
Actual Result
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/nyuszika7h/test/.venv/lib/python3.9/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/home/nyuszika7h/test/.venv/lib/python3.9/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/home/nyuszika7h/test/.venv/lib/python3.9/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/home/nyuszika7h/test/.venv/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/home/nyuszika7h/test/.venv/lib/python3.9/site-packages/requests/adapters.py", line 416, in send
self.cert_verify(conn, request.url, verify, cert)
File "/home/nyuszika7h/test/.venv/lib/python3.9/site-packages/requests/adapters.py", line 243, in cert_verify
conn.cert_file = cert[0]
TypeError: 'PosixPath' object is not subscriptable
Reproduction Steps
from pathlib import Path
import requests
requests.get('https://example.com', cert=Path('cert.pem'))
System Information
$ python -m requests.help
{
"chardet": {
"version": null
},
"charset_normalizer": {
"version": "2.0.5"
},
"cryptography": {
"version": ""
},
"idna": {
"version": "3.2"
},
"implementation": {
"name": "CPython",
"version": "3.9.2"
},
"platform": {
"release": "5.10.0-8-amd64",
"system": "Linux"
},
"pyOpenSSL": {
"openssl_version": "",
"version": null
},
"requests": {
"version": "2.26.0"
},
"system_ssl": {
"version": "101010bf"
},
"urllib3": {
"version": "1.26.6"
},
"using_charset_normalizer": true,
"using_pyopenssl": false
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at requests/adapters.py, specifically the cert_verify entry point shown in the traceback, and compare its handling of a single cert value with the reported string behavior. Re-run the Path('cert.pem') reproduction and consider the issue done when a single pathlib.Path is accepted like a string without the reported TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100