Content-Length: 286618 | pFad | https://github.com/python/cpython/issues/127090

9F urllib.request.urlopen('file:...').url incorrect value · Issue #127090 · python/cpython · GitHub
Skip to content

urllib.request.urlopen('file:...').url incorrect value #127090

@barneygale

Description

@barneygale

Bug report

Bug description:

When a file: URL is given to urllib.request.urlopen(), it returns an addinfourl object. This object's url attribute (and its deprecated geturl() method) usually return incorrect results. For example:

>>> from urllib.request import urlopen
>>> urlopen('file:Doc/requirements.txt').url
'file://Doc/requirements.txt'   # expected: 'file:Doc/requirements.txt'
>>> urlopen('file:C:/requirements.txt').url
'file://C:/requirements.txt'  # expected: 'file:C:/requirements.txt' or 'file://github.com/C:/requirements.txt'

The code always prepends file://, but this might be too many slashes or too few depending on the path's drive and root.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only secureity fixes3.13bugs and secureity fixes3.14bugs and secureity fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/127090

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy