TypeError:不是所有在字符串格式错误python期间转换的参数

2024-04-26 14:18:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经为我们的REST API定制了tempest代码,但是当我运行脚本时,在开始使用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

如果有人遇到这种错误,如果有人帮助我,我将不胜感激。

谢谢


Tags: inpyself脚本formatinitusrlogging
1条回答
网友
1楼 · 发布于 2024-04-26 14:18:38

使用%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,但是如果你放一个到几个,它会给出TypeError: not all arguments converted during string formatting

可能的情况是,您在结尾处的括号中插入了一个变量,但是百分比符号的数目不匹配。如果您希望我们进一步帮助您,请张贴您的代码:)

相关问题 更多 >