我是 python 和 xml-rpc 的新手,我一直在解码来自公共服务的二进制数据:
使用此代码的服务请求响应是:
from xmlrpc.client import Server
import xmlrpc.client
from pprint import pprint
DEV_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
logFile = open('stat.txt', 'w')
s1 = Server('http://muovi.roma.it/ws/xml/autenticazione/1')
s2 = Server('http://muovi.roma.it/ws/xml/paline/7')
token = s1.autenticazione.Accedi(DEV_KEY, '')
res = s2.paline.GetStatPassaggi(token)
pprint(res, logFile)
回复 :
{'id_richiesta': '257a369dbf46e41ba275f8c821c7e1e0',
'risposta': {'periodi_aggregazione': <xmlrpc.client.Binary object at 0x0000027B7D6E2588>,
'tempi_attesa_percorsi': <xmlrpc.client.Binary object at 0x0000027B7D9276D8>}}
我需要解码这两个二进制对象,并且我坚持使用以下代码:
from xmlrpc.client import Server
import xmlrpc.client
from pprint import pprint
DEV_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxx'
logFile = open('stat.txt', 'w')
s1 = Server('http://muovi.roma.it/ws/xml/autenticazione/1')
s2 = Server('http://muovi.roma.it/ws/xml/paline/7')
token = s1.autenticazione.Accedi(DEV_KEY, '')
res = s2.paline.GetStatPassaggi(token)
dat = xmlrpc.client.Binary(res)
out = xmlrpc.client.Binary.decode(dat)
pprint(out, logFile)
结束于:
回溯(最近一次调用):文件“stat.py”,第 18 行,在 dat = xmlrpc.client.Binary(res) 文件“C:\Users\Leonardo\AppData\Local\Programs\Python\Python35\lib\ xmlrpc\client.py",第 389 行,在初始化 数据中。类。名称)类型错误:预期的字节或字节数组,而不是字典
我为 xmlrpc.client 找到的唯一文档是 docs.python.org 的文档,但我不知道如何解码这些二进制文件