glance client http.py string format error

Bug #1265730 reported by Le Tian Ren
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance Client
Fix Released
Undecided
Le Tian Ren

Bug Description

Issue:
Found this coding defect when we ran into "TypeError: not all arguments converted during string formatting"

https://github.com/openstack/python-glanceclient/blob/master/glanceclient/common/http.py#L438

                msg = 'Unable to load CA from "%s"' % (self.cacert, e)

proposed fix is
msg = 'Unable to load CA from "%s" due to %s' % (self.cacert, e)

or use
msg = 'Unable to load CA from "{0}" due to {1}'.format(self.cacert, e)

or if the original author intend to use tuple to format the msg
msg = 'Unable to load CA from "%s"' % ((self.cacert, e),)

I prefer the 2nd one, .format one.

(Edited in 2014/01/06)
I'll make L438 align with L431, L416, although it is not my first choice to format string.

BTW, during fixing this bug, I found that pep8 and flake8 won't report such string
format error, but pylint can
pylint http.py | grep "format string"
E:438,22:VerifiedHTTPSConnection.setcontext: Too many arguments for format string

So I suggest the community use editor with pylint integrated for static analysis.
Mine is vim + scrooloose/syntastic(which will use pylint for python by default).
Eclipse also has pylint plugin.

Le Tian Ren (gpanda+)
Changed in glance:
assignee: nobody → Le Tian Ren (gpanda+)
Le Tian Ren (gpanda+)
Changed in glance:
status: New → Confirmed
Le Tian Ren (gpanda+)
Changed in glance:
status: Confirmed → In Progress
Le Tian Ren (gpanda+)
tags: added: low-hanging-fruit
affects: glance → python-glanceclient
Revision history for this message
reachlin (reachlin) wrote :

I think you should keep consistent on print out like in line 431

Revision history for this message
Le Tian Ren (gpanda+) wrote :

Agree, I also saw that, I will make it align with L431.

Le Tian Ren (gpanda+)
description: updated
Le Tian Ren (gpanda+)
description: updated
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-glanceclient (master)

Fix proposed to branch: master
Review: https://review.openstack.org/65036

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-glanceclient (master)

Reviewed: https://review.openstack.org/65036
Committed: https://git.openstack.org/cgit/openstack/python-glanceclient/commit/?id=2ed01afac96af59304215e384fd9b0f0be992711
Submitter: Jenkins
Branch: master

commit 2ed01afac96af59304215e384fd9b0f0be992711
Author: Le Tian Ren <email address hidden>
Date: Mon Jan 6 14:43:56 2014 +0800

    Fix glanceclient http.py string formatting error

    * Fix "TypeError: not all arguments converted during string formatting"

    * Add a UT case to cover the path where the bug is in

    Change-Id: I91a137c5c3a9a3cc603804bef5eaea14ae281c08
    Closes-Bug: #1265730

Changed in python-glanceclient:
status: In Progress → Fix Committed
Louis Taylor (kragniz)
Changed in python-glanceclient:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.