[issue10367] "python setup.py sdist upload --show-response" can fail with "UnboundLocalError: local variable 'result' referenced before assignment"
Jesús Cea Avión
report at bugs.python.org
Mon Nov 8 22:36:52 CET 2010
New submission from Jesús Cea Avión <jcea at jcea.es>:
Uploading a new release of one of my libraries to PYPI I got this error:
"""
Submitting dist/bsddb3-5.1.1.tar.gz to http://pypi.python.org/pypi
Upload failed (400): A file named "bsddb3-5.1.1.tar.gz" already exists for bsddb3-5.1.1. To fix problems with that file you should create a new release.
Traceback (most recent call last):
File "setup.py", line 5, in <module>
import setup2
File "/home/pybsddb/setup2.py", line 415, in <module>
'Programming Language :: Python :: 3.2',
File "/usr/local/lib/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/local/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/local/lib/python2.7/distutils/command/upload.py", line 60, in run
self.upload_file(command, pyversion, filename)
File "/usr/local/lib/python2.7/distutils/command/upload.py", line 189, in upload_file
self.announce('-'*75, result.read(), '-'*75)
UnboundLocalError: local variable 'result' referenced before assignment
"""
Checking the code, I see this:
"""
# send the data
try:
result = urlopen(request)
status = result.getcode()
reason = result.msg
except socket.error, e:
self.announce(str(e), log.ERROR)
return
except HTTPError, e:
status = e.code
reason = e.msg
if status == 200:
self.announce('Server response (%s): %s' % (status, reason),
log.INFO)
else:
self.announce('Upload failed (%s): %s' % (status, reason),
log.ERROR)
if self.show_response:
self.announce('-'*75, result.read(), '-'*75)
"""
Here, if we selected "show_response" *AND* some error happens, "result" will be undefined and the last line will fail.
This bug was introduced in Python 2.7. It used to work correctly under Python 2.6.
I didn't check Python 3.x.
I think this bug is trivial to reproduce: just try to upload any file with no permissions for it, using "--show_response" command line option.
----------
keywords: easy
messages: 120804
nosy: jcea
priority: high
severity: normal
stage: needs patch
status: open
title: "python setup.py sdist upload --show-response" can fail with "UnboundLocalError: local variable 'result' referenced before assignment"
type: crash
versions: Python 2.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10367>
_______________________________________
More information about the Python-bugs-list
mailing list