我想知道是否可以得到一些帮助,我的代码粘贴在下面。现在它运行并完成ping任务,但运行到以下错误。任何帮助都会很棒,因为我一直在努力一段时间。Python,Django和stdout的奇怪问题
错误:
Server.objects.filter(pk=id[0]).update(online=1)
TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'
代码:
import subprocess
from django.db import models
from networkstats.models import Server
query = Server.objects.values_list('id', 'ip_address')
for ip_address in query:
print 'Server ID: ' + str(ip_address[0])
print 'Server IP: ' + str(ip_address[1])
command = ['ping -t 200 -c 1 ' + ip_address[1]]
ping = subprocess.Popen(command, stdout=subprocess.PIPE, shell = True)
if "100% pocket loss" in ping.stdout.read():
Server.objects.filter(pk=id[0]).update(online=0)
else:
Server.objects.filter(pk=id[0]).update(online=1)
谢谢你的帮助,改变和纠正“口袋损失”允许它正确更新。 – icebox3d
@ icebox3d查看更新的代码 – neoascetic