0
我有大約100臺運行Mersive Solstice的機器,這是一個無線顯示工具。我試圖收集一些重要的信息,特別是每個安裝實例的許可證的履行ID。Mersive Solstive API:AttributeError:'dict'對象沒有屬性'm_displayInformation'
使用Solstice OpenControl API,發現here,我掀起了一個python腳本來抓取我需要的所有東西,使用json GET。但是,使用的例子,即使從文檔GET,
import requests
import json
url = ‘http://ip-of-machine/api/stats’
r = requests.get(url)
jsonStats = json.loads(r.text)
usersConnected = jsonStats.m_statistics.m_connectedUsers
我遇到:
Traceback (most recent call last):
File "C:/Python27/test.py", line 7, in <module>
usersConnected = jsonStats.m_statistics.m_connectedUsers
AttributeError: 'dict' object has no attribute 'm_statistics'
這是非常混亂。關於這個問題,我在SO上發現了很多類似的問題,但沒有一個專門針對來自API參考指南的錯誤GET請求。
此外,這裏是我的腳本:
import requests
import json
from time import sleep
url = 'test'
f = open("ip.txt", "r")
while(url != ""):
url = f.readline()
url = url.rstrip('\n')
print(url)
try:
r = requests.get(url)
except:
sleep(5)
jsonConfig = json.loads(r.text)
displayName = jsonConfig.m_displayInformation.m_displayName
hostName = jsonConfig.m_displayInformation.m_hostName
ipv4 = jsonConfig.m_displayInformation.m_ipv4
fulfillmentId = jsonConfig.m_licenseCuration.fulfillmentId
r.close()
f.close
我導入的URL從易飼養文本文檔。我能夠連接到/ api/config JSON,並且當URL被放入瀏覽器時,它會吐出JSON記錄:
大約5分鐘前,我決定將我的符號從點切換到括號,這當然有訣竅。我回到自己的答案,但是你描述的問題比我的要好得多!乾杯! – Dupontrocks11