我正在尝试从一个内部项目(http:\192.168.1.15:8082)中提取数据。它使用json-rpc 2.0。一开始,我试着用美容汤检索信息,因为它是在屏幕上显示的,但这不起作用,我得到的只是一堆函数代码。我不熟悉json-rpc。欢迎任何帮助。
网站上打印的回复数据如下所示:
响应:
{"jsonrpc":"2.0","result":[{"uri":"Geometry","time":1537525006,"geo":{"type":"characteristic","id":125,"information2":{"type":"Point","Weight":[15.362154,196.623546]}如何检索此信息?
谢谢大家
尼克
发布于 2018-09-21 19:49:09
看看requests https://pypi.org/project/requests
要遵守该标准,您需要将payload放入您的请求,否则它只是一个普通的post
import requests
import json
def main():
url = "http://192.168.1.15:8082/jsonrpc"
headers = {'content-type': 'application/json'}
# Example echo method
payload = {
"method": "your_method_name",
"jsonrpc": "2.0",
"id": 0,
}
response = requests.post(
url, data=json.dumps(payload), headers=headers).json()
print(response)
print(response['result']['uri'])
print(response['result']['time'])
print(response['result']['geo'])
print(response['result']['geo']['id'])
print(response['result']['geo']['type'])
print(response['result']['geo']['information2'])
print(response['result']['geo']['information2']['type'])
print(response['result']['geo']['information2']['Weight'])
if __name__ == "__main__":
main()如果您想要特定于json_rpc的东西,那么可以看看jsonrpc_requests https://pypi.org/project/jsonrpc-requests/
请注意,在这个示例中,响应的反序列化是如何为您处理的,并且您只会返回方法调用的结果,而不是整个响应。
from jsonrpc_requests import Server
def main():
url = "http://localhost:8082/jsonrpc"
server = Server(url)
result = server.dosomething()
print(result)
print(result['uri'])
print(result['time'])
print(result['geo'])
print(result['geo']['id'])
print(result['geo']['type'])
print(result['geo']['information2'])
print(result['geo']['information2']['type'])
print(result['geo']['information2']['Weight'])
if __name__ == "__main__":
main()https://stackoverflow.com/questions/52441692
复制相似问题