PyDocs

Nav

Internet Protocols and Support

url2pathname

urllib.request

function (source) not WASI
  • url2pathname(url, *, require_scheme=False, resolve_host=False)
Convert the given file URL to a local file system path.

The 'file:' scheme prefix must be omitted unless *require_scheme*
is set to true.

The URL authority may be resolved with gethostbyname() if
*resolve_host* is set to true.
Changed in 3.14
  • 3.14: Windows drive letters are no longer converted to uppercase, and : characters not following a drive letter no longer cause an OSError exception to be raised on Windows.
  • 3.14: The URL authority is discarded if it matches the local hostname. Otherwise, if the authority isn’t empty or localhost, then on Windows a UNC path is returned (as before), and on other platforms a URLError is raised.
  • 3.14: The URL query and fragment components are discarded if present.
  • 3.14: The require_scheme and resolve_host parameters were added.
1 Example
>>> from urllib.request import url2pathname
>>> url = 'file:///C:/Program%20Files'
>>> url2pathname(url, require_scheme=True)
'C:\\Program Files'
from the Python docs
See Also
No see-alsos for urllib.request/url2pathname
0 Notes
No notes for url2pathname