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

Windows paths with driver letters not supported #31

Closed
FelixSchwarz opened this issue Apr 18, 2024 · 2 comments
Closed

Windows paths with driver letters not supported #31

FelixSchwarz opened this issue Apr 18, 2024 · 2 comments

Comments

@FelixSchwarz
Copy link

I'm trying to use requests-file on Windows using an absolute path like this: "file://C:/foo/bar".

The problem is that the current code uses urlparse() and .netloc contains "C:" in that case which triggers an exception:

if url_parts.netloc and url_parts.netloc != "localhost":

Just to demonstrate the problem:

>>> from requests.compat import urlparse
>>> urlparse('file://C:/foo/bar')
ParseResult(scheme='file', netloc='C:', path='/foo/bar', params='', query='', fragment='')

Background: I'm trying to add support for local repositories in conda-lock and that project tries to support also Windows users.

Do you think we could add a workaround to support Windows drive letters? (just on Windows)

@dashea
Copy link
Owner

dashea commented Apr 18, 2024

Hi. There are a handful of ways to express windows paths containing drive letters as file URIs. This is not one of them. Two /'s after the file: indicates that the next component is a hostname, which is allowed in the file URI format for certain platform-specific non-local file locations, and that isn't what you want here.

Here's how the urlparse results look using a few of the examples from RFC 8089:

>>> urlparse('file:///C:/foo/bar')
ParseResult(scheme='file', netloc='', path='/C:/foo/bar', params='', query='', fragment='')
>>> urlparse('file:///C|/foo/bar')
ParseResult(scheme='file', netloc='', path='/C|/foo/bar', params='', query='', fragment='')
>>> urlparse('file:C:/foo/bar')
ParseResult(scheme='file', netloc='', path='C:/foo/bar', params='', query='', fragment='')

There is handling for both the C: and C| style of drive letters in URIs. Hope this helps.

@dashea dashea closed this as completed Apr 18, 2024
@FelixSchwarz
Copy link
Author

Doh - somehow I missed that. Thank you very much for the explanation.

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

No branches or pull requests

2 participants