This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: URLError invoked with reason as filename
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: chris.jerdonek, ezio.melotti, ncoghlan, orsenthil, pitrou, python-dev
Priority: normal Keywords: easy, patch

Created on 2012-10-16 16:18 by chris.jerdonek, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue16250.patch orsenthil, 2012-10-22 00:55 review
Messages (12)
msg173058 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-10-16 16:18
This issue is to fix invocations of URLError so that "reasons" are not passed in for the "filename" argument of the URLError constructor.

Ezio found and described this issue when commenting on issue 10836:

  http://bugs.python.org/issue10836#msg172988

In more detail: URLError accepts "reason" and "filename" arguments:

http://hg.python.org/cpython/file/74b95194ba86/Lib/urllib/error.py#l23

However, in several places in Lib/urllib, URLError is invoked with a "reason" passed in for the filename.  For example:

    raise URLError('local file error', 'not on local host')

This issue could be addressed for this example by changing the above to:

    raise URLError('local file error: not on local host')

This dovetails with issue #16247, which is to start passing the actual filename in for some calls to URLError (and perhaps to adjust URLError's __str__, etc).
msg173060 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-10-16 16:52
> raise URLError('local file error: not on local host')

I should also point out that URLError invocations with formats like the above already do occur in Lib/urllib/request.py.  For example:

    raise URLError('ftp error: no host given')
    exc = URLError('ftp error: %s' % msg)
    raise URLError("http protocol error: bad status line")
msg173112 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-10-16 23:39
For future reference, this affects 3.2 onwards.  It probably makes sense to address this in the same branches in which we plan to address issue 16247 (currently set to 3.3 onwards).
msg173493 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-10-22 00:55
This patch fixed these URLError wrong invocation issue and adds some tests for testing those it. 

I noticed that some of these were in the dead-end of the code, like checking if url is not a str (it is always, unwrap makes it a str if otherwise). Those will have to be cleaned and I shall do it next.
msg173495 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-10-22 02:03
New changeset 8fb438e7f738 by Senthil Kumaran in branch 'default':
Issue #16250: Fix the invocations of URLError which had misplaced filename attribute for exception
http://hg.python.org/cpython/rev/8fb438e7f738
msg173496 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-10-22 02:06
This is fixed in 3.4. I shall backport to other branches.
msg173565 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-10-22 21:16
This broke the Windows 7 buildbot:
http://buildbot.python.org/all/builders/AMD64%20Windows7%20SP1%203.x/builds/850
msg173573 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-10-23 00:41
The change in 49de26395d1a addresses the buildbot failure. I have given a run again.
msg173579 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-10-23 04:52
The change I had made for fixing the windows buildbot had not fixed it. I  am skipped (1f92315d9568) the test on windows, investigating the reason for windows behavior and I shall remove the skiptest on windows after fix.
msg173914 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-10-27 09:51
New changeset 5e71f2712076 by Senthil Kumaran in branch '3.2':
Issue #16250: Fix URLError invocation with proper args.
http://hg.python.org/cpython/rev/5e71f2712076

New changeset 30547e2cd04d by Senthil Kumaran in branch '3.3':
Issue #16250: Fix URLError invocation with proper args
http://hg.python.org/cpython/rev/30547e2cd04d
msg173916 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-10-27 10:48
New changeset 3fb84c1da8c5 by Senthil Kumaran in branch '2.7':
Add some tests in 2.7 for Issue #16250
http://hg.python.org/cpython/rev/3fb84c1da8c5
msg173919 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-10-27 10:52
This is fixed in all versions now.
History
Date User Action Args
2022-04-11 14:57:37adminsetgithub: 60454
2012-10-27 10:52:27orsenthilsetstatus: open -> closed
messages: + msg173919

assignee: orsenthil
resolution: fixed
stage: needs patch -> resolved
2012-10-27 10:48:57python-devsetmessages: + msg173916
2012-10-27 09:51:21python-devsetmessages: + msg173914
2012-10-23 04:52:03orsenthilsetmessages: + msg173579
2012-10-23 00:41:43orsenthilsetmessages: + msg173573
2012-10-22 21:16:29pitrousetnosy: + pitrou
messages: + msg173565
2012-10-22 02:06:22orsenthilsetmessages: + msg173496
2012-10-22 02:03:51python-devsetnosy: + python-dev
messages: + msg173495
2012-10-22 00:55:34orsenthilsetfiles: + issue16250.patch
keywords: + patch
messages: + msg173493
2012-10-16 23:39:49chris.jerdoneksetstage: needs patch
messages: + msg173112
versions: + Python 3.3
2012-10-16 16:52:05chris.jerdoneksetmessages: + msg173060
2012-10-16 16:43:54ezio.melottisetnosy: + ncoghlan
2012-10-16 16:23:30orsenthilsetnosy: + orsenthil
2012-10-16 16:18:12chris.jerdonekcreate