-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
cert
parameter does not accept a single pathlib.Path
object as argument
#5936
Comments
cert
parameter does not accept pathlib.Path
objectscert
parameter does not accept a single pathlib.Path
object as argument
Hi @nyuszika7h, this seems like a reasonable request but is going to be somewhat difficult to implement prior to dropping 2.7 support. We don't intend to add backports as a dependency, so we'll leave this a todo for when the project finally moves to only Python 3 support. Thanks! |
I don't think this is entirely reasonable as pathlib is garabage. Expecting it to just work in places clearly documented as accepting either |
How exactly is it "garbage"? It has existed since Python 3.4 and is becoming a standard, take it up with the Python maintainers, not me. If you're developing a standalone program you have every right to not use pathlib if you don't like it, but developers of a major library used by thousands of other developers should consider supporting it regardless of their personal views. It doesn't really add any undue maintenance burden either.
|
It makes sense that it would be a good idea to allow some sort of path-like object, even without specifying examples of path-like object types with type hinting. If you look at https://docs.python.org/3/glossary.html#term-path-like-object and https://docs.python.org/3/library/os.html#os.PathLike, it shouldn't be unreasonable to check if an object is path-like. The docs do mention here that We can replace... Lines 241 to 247 in e8a9bd7
With... if cert:
if not isinstance(cert, basestring):
# 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 Though I've never used If |
While requests still supports Python 2, it's probably better to use |
Hi all, Just combing through issues in some of my favorite python libs looking for ways to contribute. Seems y'all have dropped support for Python 2 in the requests library, so this might be a great thing to implement at this time, unless there's something I'm not understanding fully. I'm looking for issues good for a GitHub newbie to tackle. And, while I would love to help with this, it seems @steveberdy has a solution in the notes above, so I wouldn't want to steal thunder by patching in code they've written. Sorry for any misunderstandings and hope this helps. |
This issue is still ongoing with v2.28.2. I think I'll make a PR since this doesn't exactly break the rules for the indefinite feature-freeze. |
requests seems to have special handling for when the
cert
parameter is a singlestr
, but does not extend the same special handling topathlib.Path
, meaning currently you either have to docert=str(path)
orcert=(path, path)
.Expected Result
Path
objects should be handled just likestr
.Actual Result
Reproduction Steps
System Information
The text was updated successfully, but these errors were encountered: