我为我们的REST API定制了暴风代码,但是当我运行脚本时,在开头使用nosetests会产生一些奇怪的类型错误,如下所述,尽管脚本中的测试用例传递
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
有人遇到过这种类型的错误,如果有人帮助我,我会很感激。
谢谢,
答案 0 :(得分:13)
使用%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
>>>
如果您添加的%s
太多,则会产生TypeError: not enough arguments for format string
,但如果您将其中一个设为{1}},则会提供TypeError: not all arguments converted during string formatting
。
您可能最后在括号中放置了一个变量,但百分号的数量不匹配。如果您希望我们为您提供进一步的帮助,请发布您的代码:)