我是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)
回应:
^{pr2}$我需要解码这两个二进制对象,而我却被这段代码困住了:
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)
最后是:
Traceback (most recent call last): File "stat.py", line 18, in dat = xmlrpc.client.Binary(res) File "C:\Users\Leonardo\AppData\Local\Programs\Python\Python35\lib\xmlrpc\client.py", line 389, in init data.class.name) TypeError: expected bytes or bytearray, not dict
我找到的唯一的医生xmlrpc.client是那个在吗docs.python.org,但我不知道如何解码这些二进制文件
如果
res
变量的内容(从2nd(s2
)服务器获得的内容是粘贴到问题中的响应,那么您应该将2nd片段的最后3行修改为(因为res
字典中已有2个Binary
对象):注意事项:
DEV_KEY
(显然)是假的相关问题 更多 >
编程相关推荐