TypeError:并非所有参数都在字符串格式化错误python期间转换

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23379327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 02:53:13  来源:igfitidea点击:

TypeError: not all arguments converted during string formatting error python

python

提问by Vinay D

I have customized tempest code for our REST API's, but when i run the scripts, using nosetests at the beginning it gives some weird type error as mentioned below, though test cases in the script passes

我已经为我们的 REST API 定制了暴风雨代码,但是当我运行脚本时,在开始时使用鼻子测试它会给出一些奇怪的类型错误,如下所述,尽管脚本中的测试用例通过了

Traceback (most recent call last):
  File "/usr/lib64/python2.6/logging/__init__.py",line 776, in emit msg = self.format(record)
  File "/usr/lib64/python2.6/logging/__init__.py", line 654, in format return fmt.format(record)
  File "/home/rmcbuild/repository/rmc-test/tempest/openstack/common/log.py", line 516, in format return logging.Formatter.format(self, record)
  File "/usr/lib64/python2.6/logging/__init__.py", line 436, in format record.message = record.getMessage()
  File "/usr/lib64/python2.6/logging/__init__.py", line 306, in getMessage msg = msg % self.args
 TypeError: not all arguments converted during string formatting

has anyone come across this type of error, would appreciate if someone helps me out of it.

有没有人遇到过这种类型的错误,如果有人帮我解决,我将不胜感激。

Thanks,

谢谢,

回答by A.J. Uppal

This happens when using %sto print a string:

%s用于打印字符串时会发生这种情况:

>>> x = 'aj8uppal'
>>> print 'Hello, %s %s' %(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not enough arguments for format string
>>> print 'Hello, ' %(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
>>> 

If you put one too many %ss, it gives a TypeError: not enough arguments for format string, but if you put one to few, it gives TypeError: not all arguments converted during string formatting.

如果你放一个太多%s,它会给出一个TypeError: not enough arguments for format string,但如果你放一个到几个,它会给出TypeError: not all arguments converted during string formatting

What is likely is that you have put a variable(s) in parentheses at the end, but the number of percent signs does not match. Please post your code if you want us to help you further :)

可能是您在最后的括号中放置了一个变量,但百分号的数量不匹配。如果您希望我们进一步帮助您,请发布您的代码:)