Skip to content

NameError in urllib.request.URLopener.retrieve #81129

Closed

Description

@tirkarthi
BPO 36948
Nosy @db3l, @berkerpeksag, @csabella, @tirkarthi
PRs
  • bpo-36948: Fix NameError in urllib.request.URLopener.retrieve #13389
  • [3.7] bpo-36948: Fix NameError in urllib.request.URLopener.retrieve (GH-13389) #13422
  • bpo-36948: Fix test_urlopener_retrieve_file on Windows #13476
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-05-21.23:01:02.528>
    created_at = <Date 2019-05-17.16:09:52.421>
    labels = ['3.8', 'type-bug', 'library']
    title = 'NameError in urllib.request.URLopener.retrieve'
    updated_at = <Date 2019-05-22.02:19:02.045>
    user = 'https://github.com/tirkarthi'

    bugs.python.org fields:

    activity = <Date 2019-05-22.02:19:02.045>
    actor = 'xtreak'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-05-21.23:01:02.528>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2019-05-17.16:09:52.421>
    creator = 'xtreak'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36948
    keywords = ['patch']
    message_count = 10.0
    messages = ['342733', '342850', '342851', '343103', '343108', '343110', '343114', '343124', '343125', '343139']
    nosy_count = 4.0
    nosy_names = ['db3l', 'berker.peksag', 'cheryl.sabella', 'xtreak']
    pr_nums = ['13389', '13422', '13476']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue36948'
    versions = ['Python 3.8']

    Activity

    1. tirkarthi commented on May 17, 2019

      @tirkarthi
      MemberAuthor

      In bpo-27485 the deprecated functions were replaced with underscore prefixed ones due to which imports where modified. Some of the places where not changed causing NameError in using urllib.request.URLopener.retrieve for local files and non-local files which is deprecated. I found these undefined names while running flake8 on Lib folder. I will raise a PR with tests for the same.

      Sample Error :

      ./python.exe
      Python 3.8.0a4+ (heads/master:870b035bc6, May 17 2019, 16:28:23)
      [Clang 7.0.2 (clang-700.1.81)] on darwin
      Type "help", "copyright", "credits" or "license" for more information.
      >>> from urllib.request import URLopener
      >>> URLopener().retrieve('file:///tmp/a.txt')
      sys:1: DeprecationWarning: URLopener style of invoking requests is deprecated. Use newer urlopen functions/methods
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/urllib/request.py", line 1786, in retrieve
          return url2pathname(splithost(url1)[1]), hdrs
      NameError: name 'splithost' is not defined
    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on May 17, 2019
    3. berkerpeksag commented on May 19, 2019

      @berkerpeksag
      Member

      New changeset c661b30 by Berker Peksag (Xtreak) in branch 'master':
      bpo-36948: Fix NameError in urllib.request.URLopener.retrieve (GH-13389)
      c661b30

    4. berkerpeksag commented on May 19, 2019

      @berkerpeksag
      Member

      Thanks! Apparently, backport to 3.7 isn't needed, so I just closed PR 13422.

    5. db3l commented on May 21, 2019

      @db3l
      Contributor

      Since this patch was introduced to the 3.x branch my Windows 7 and 10 buildbots have been failing in test_urlopener_retrieve_file. See https://buildbot.python.org/all/#/builders/3/builds/2661 for the first such failure on the Win10 worker.

      The problem appears to be related to those workers having an explicit TEMP folder that happens to use a lowercase drive letter, causing the test assertion to fail due to differing case in the drive letter.

      While I could work around this by changing my builder TEMP definition, the test seems fragile on case-insensitive filesystems, so perhaps it should be comparing a normalized path instead?

    6. berkerpeksag commented on May 21, 2019

      @berkerpeksag
      Member

      Thank you for the heads up, David. Could you please take a look at PR 13476?

    7. db3l commented on May 21, 2019

      @db3l
      Contributor

      Yes, PR 13476 tested locally on the Win10 builder resolves the error.

    8. db3l commented on May 21, 2019

      @db3l
      Contributor

      Oh, and just for historical purposes, it looks like the root cause was that the nturl2path.pathnametourl forces an uppercase drive letter. So that's where the inconsistency in the test got introduced.

    9. berkerpeksag commented on May 21, 2019

      @berkerpeksag
      Member

      New changeset 2725cb0 by Berker Peksag in branch 'master':
      bpo-36948: Fix test_urlopener_retrieve_file on Windows (GH-13476)
      2725cb0

    10. berkerpeksag commented on May 21, 2019

      @berkerpeksag
      Member

      Thanks!

    11. tirkarthi commented on May 22, 2019

      @tirkarthi
      MemberAuthor

      Thank you David and Berker.

    12. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.8 (EOL)end of lifestdlibStandard 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