homepage

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: format str bug in urllib request.py
Type: behavior Stage: resolved
Components: Library (Lib), Tests Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, ezio.melotti, georg.brandl, giampaolo.rodola, pitrou, r.david.murray, rock, serhiy.storchaka
Priority: high Keywords: patch

Created on 2013年05月08日 00:50 by pitrou, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
urllib-request-format-type-bug.patch rock, 2013年07月18日 15:02 review
Messages (11)
msg188699 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013年05月08日 00:50
The following error appeared on some buildbots:
http://buildbot.python.org/all/builders/x86%20Gentoo%203.x/builds/4195/steps/test/logs/stdio
======================================================================
ERROR: test_ftp (test.test_urllib2net.OtherNetworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/var/lib/buildslave/3.x.murray-gentoo/build/Lib/urllib/request.py", line 2337, in retrfile
 self.ftp.cwd(file)
 File "/var/lib/buildslave/3.x.murray-gentoo/build/Lib/ftplib.py", line 622, in cwd
 return self.voidcmd(cmd)
 File "/var/lib/buildslave/3.x.murray-gentoo/build/Lib/ftplib.py", line 272, in voidcmd
 return self.voidresp()
 File "/var/lib/buildslave/3.x.murray-gentoo/build/Lib/ftplib.py", line 245, in voidresp
 resp = self.getresp()
 File "/var/lib/buildslave/3.x.murray-gentoo/build/Lib/ftplib.py", line 240, in getresp
 raise error_perm(resp)
ftplib.error_perm: 550 Failed to change directory.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
 File "/var/lib/buildslave/3.x.murray-gentoo/build/Lib/test/test_urllib2net.py", line 112, in test_ftp
 self._test_urls(urls, self._extra_handlers())
 File "/var/lib/buildslave/3.x.murray-gentoo/build/Lib/test/test_urllib2net.py", line 218, in _test_urls
 f = urlopen(url, req, TIMEOUT)
 File "/var/lib/buildslave/3.x.murray-gentoo/build/Lib/test/test_urllib2net.py", line 33, in wrapped
 return _retry_thrice(func, exc, *args, **kwargs)
 File "/var/lib/buildslave/3.x.murray-gentoo/build/Lib/test/test_urllib2net.py", line 23, in _retry_thrice
 return func(*args, **kwargs)
 File "/var/lib/buildslave/3.x.murray-gentoo/build/Lib/urllib/request.py", line 462, in open
 response = self._open(req, data)
 File "/var/lib/buildslave/3.x.murray-gentoo/build/Lib/urllib/request.py", line 480, in _open
 '_open', req)
 File "/var/lib/buildslave/3.x.murray-gentoo/build/Lib/urllib/request.py", line 440, in _call_chain
 result = func(*args)
 File "/var/lib/buildslave/3.x.murray-gentoo/build/Lib/urllib/request.py", line 1464, in ftp_open
 fp, retrlen = fw.retrfile(file, type)
 File "/var/lib/buildslave/3.x.murray-gentoo/build/Lib/urllib/request.py", line 2339, in retrfile
 raise URLError('ftp error: %d' % reason) from reason
TypeError: %d format: a number is required, not error_perm
msg193301 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2013年07月18日 14:55
I cannot reproduce the issue on Ubuntu.
As for the second exception I think it's safe to just do:
- raise URLError('ftp error: %d' % reason) from reason
+ raise URLError('ftp error: %s' % reason) from reason
(will commit that later)
msg193303 - (view) Author: Rock Lee (rock) Date: 2013年07月18日 15:02
Bug in urllib/request.py.
format string formatted error type variable 
 2373 except ftplib.error_perm as reason:
 2374 raise URLError('ftp error: %d' % reason) from reason
variable reason here is a instance of class ftplib.error_perm.
We need to passed in a integer object. 
Patch supplied.
msg193304 - (view) Author: Rock Lee (rock) Date: 2013年07月18日 15:03
Fixed like this:
raise URLError('ftp error: %d' % int(str(reason)[:3])) from reason
I think this is the original author's intention. 
Actually, need to fix two places in urllib/request.py
msg193305 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2013年07月18日 15:07
That's not safe as a misbehaving FTP server might not send a response code at all (highly unlikely but still...).
Furthermore having the complete server response (response code + accompaining message) is a lot more helpful.
msg193307 - (view) Author: Rock Lee (rock) Date: 2013年07月18日 15:13
yes, the malformed server could do evil things. If we need to cover this situation, we need to some extra fixes in this file. 
Maybe the exception message look like this is the better one ?
 ftplib.error_perm: 550 Failed to change directory
msg193308 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2013年07月18日 15:21
I think "raise URLError('ftp error: %s' % reason) from reason" is just fine.
msg193309 - (view) Author: Rock Lee (rock) Date: 2013年07月18日 15:34
Yes, the simplest fix is just replace '%d' to '%s'.
Line 2362 and 2374 all need to modify.
msg193529 - (view) Author: Rock Lee (rock) Date: 2013年07月22日 12:27
Any progress for this issue?
I changed the title of the issue.
msg201447 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013年10月27日 11:36
Giampaolo's suggestion LGTM.
msg201846 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013年10月31日 20:26
This was changed to %r by Benjamin Peterson in 27e470952085.
History
Date User Action Args
2022年04月11日 14:57:45adminsetgithub: 62133
2013年10月31日 20:26:31r.david.murraysetstatus: open -> closed
resolution: out of date
messages: + msg201846

stage: needs patch -> resolved
2013年10月27日 11:38:14serhiy.storchakasetnosy: + georg.brandl
2013年10月27日 11:36:45serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg201447
2013年07月31日 06:51:30Arfreversetnosy: + Arfrever
2013年07月22日 12:27:18rocksetmessages: + msg193529
title: test_ftp failure / ftplib error formatting issue -> format str bug in urllib request.py
2013年07月18日 15:34:04rocksetmessages: + msg193309
2013年07月18日 15:21:52giampaolo.rodolasetmessages: + msg193308
2013年07月18日 15:13:13rocksetmessages: + msg193307
2013年07月18日 15:07:40giampaolo.rodolasetmessages: + msg193305
2013年07月18日 15:03:41rocksetmessages: + msg193304
2013年07月18日 15:02:25rocksetfiles: + urllib-request-format-type-bug.patch

nosy: + rock
messages: + msg193303

keywords: + patch
2013年07月18日 14:55:10giampaolo.rodolasetmessages: + msg193301
2013年07月18日 14:46:41ezio.melottisetnosy: + ezio.melotti
2013年05月08日 00:50:24pitroucreate

AltStyle によって変換されたページ (->オリジナル) /