我可以跑:
import chef
chef.autoconfigure()
for node in chef.Node.list():
if "auto" in node.lower():
print "deleting node " + node
nodeObj = chef.Node(node)
nodeObj.delete()
直接在控制台中,但是当我尝试将其作为脚本运行时:python2.7 test.py
我收到以下错误:
Traceback (most recent call last):
File "test.py", line 38, in <module>
for node in chef.Node.list():
File "/usr/local/lib/python2.7/site-packages/chef/base.py", line 86, in list
names = [name for name, url in api[cls.url].iteritems()]
TypeError: 'NoneType' object has no attribute '__getitem__'
我使用控制台验证
>>> chef.__path__
['/usr/local/lib/python2.7/site-packages/chef']
所以,机器是一样的,python的版本是一样的,模块是一样的。为什么这可能发生?