Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TypeError: not all arguments converted during string formatting

78 views
Skip to first unread message

Ganesh Pal

unread,
Feb 17, 2016, 8:59:10 AM2/17/16
to
Hi Team,


Iam on python 2.6 and Linux , I had replaced print out, err ret with
logging.info(out, err ,ret) in the below code . I am getting

"TypeError: not all arguments converted during string formatting"
error any quick suggestion


try:
out, err, ret = run(cmd, timeout=60)
# New line added below
logging.info(out, err ,ret)
if ret != 0:
logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret))
raise Exception("Preparing cluster failed...Exiting !!!")
except Exception as e:
logging.exception("Failed to run %s got %s" % (cmd, e))
sys.exit("Preparing cluster failed")
logging.info("Preparing Cluster.....Done !!!")


(Pdb) c
Traceback (most recent call last):
File "/usr/local/lib/python2.6/logging/__init__.py", line 755, in emit
File "/usr/local/lib/python2.6/logging/__init__.py", line 637, in format
File "/usr/local/lib/python2.6/logging/__init__.py", line 425, in format
File "/usr/local/lib/python2.6/logging/__init__.py", line 295, in getMessage
TypeError: not all arguments converted during string formatting


Regards,
Ganesh

Ganesh Pal

unread,
Feb 17, 2016, 9:00:38 AM2/17/16
to
I think logging.info(out) works the problem is when I add
logging.info(out,err,ret) ,may be there is a better way to supply this
arguments

Chris Angelico

unread,
Feb 17, 2016, 9:02:23 AM2/17/16
to
On Thu, Feb 18, 2016 at 12:58 AM, Ganesh Pal <ganes...@gmail.com> wrote:
> Iam on python 2.6 and Linux , I had replaced print out, err ret with
> logging.info(out, err ,ret) in the below code . I am getting
>
> "TypeError: not all arguments converted during string formatting"
> error any quick suggestion
>

The print statement/function happily accepts multiple arguments, and
will join them according to a set of predefined rules. The logging
functions don't have those rules, so they take one message and some
optional parameters. Try this, instead:

logging.info("%r %r %r", out, err, ret)

and then tweak the format string according to requirements. For a
quick dump, this will serve you well.

ChrisA

Ganesh Pal

unread,
Feb 18, 2016, 10:42:42 AM2/18/16
to
On Wed, Feb 17, 2016 at 7:32 PM, Chris Angelico <ros...@gmail.com> wrote:

> The print statement/function happily accepts multiple arguments, and
> will join them according to a set of predefined rules. The logging
> functions don't have those rules, so they take one message and some
> optional parameters. Try this, instead:
>
> logging.info("%r %r %r", out, err, ret)
>

Thanks this solved my issue :)
0 new messages