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
NameError in urllib.request.URLopener.retrieve #81129
Comments
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 |
Thanks! Apparently, backport to 3.7 isn't needed, so I just closed PR 13422. |
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? |
Thank you for the heads up, David. Could you please take a look at PR 13476? |
Yes, PR 13476 tested locally on the Win10 builder resolves the error. |
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. |
Thanks! |
Thank you David and Berker. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: