0

私は 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>}}

これらの 2 つのバイナリ オブジェクトをデコードする必要があり、次のコードに行き詰まっています。

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 行目、初期 データ。クラスname ) TypeError: dict ではなく、bytes または bytearray が必要です

xmlrpc.client について見つけた唯一のドキュメントは docs.python.org のものですが、これらのバイナリをデコードする方法がわかりません

4

1 に答える 1