2016-09-08 11 views
0

내가 파이썬과 XMLRPC에 새로 온 사람, 나는 공공 서비스에서 오는 바이너리 데이터를 디코딩와 붙어있어 :디코딩 진

이 코드로 서비스 요청 응답은 다음과 같습니다

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) 

:

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의 하나이지만, 나는이 바이너리를 디코딩 할 수있는 방법을 알아낼 수 없습니다

+1

올바른 통화를하고있는 것 같습니다. 문제는 웹 사이트에 있습니까? 'TypeError : 예상 바이트 또는 bytearray,하지 dict'? 나는 당신이 실제로 '버라이어터'대신에 버티컬을받는다고 생각할 것이다. – NeoVe

+1

네, 나는 그것이 딕트라고 생각합니다. 나는 웹 사이트 개발자에게 연락하려고 노력할 것이다. – Forzaferrarileo

답변

0

res 변수 (당신이 2 (s2) 서버에서 무엇을 얻을)의 내용은 질문에 붙여 넣을 응답이, 당신은 당신으로 (로 2 조각의 마지막 3 줄을 수정해야하는 경우 이미 2 Binary 있습니다.

# Existing code 
res = s2.paline.GetStatPassaggi(token) 

answer = res.get("risposta", dict()) 
aggregation_periods = answer.get("periodi_aggregazione", xmlrpc.client.Binary()) 
timeout_paths = answer.get("tempi_attesa_percorsi", xmlrpc.client.Binary()) 

print(aggregation_periods.data) 
print(timeout_paths.data) 

:

  • 따르면 [Python]: Binary Objects에 다음 res사전)에있는 개체는

    Binary objects have the following methods, supported mainly for internal use by the marshalling/unmarshalling code:

  • 나는 연결할 수 없습니다 (이 테스트 솔루션) , 이후 DEV_KEY (가짜) 가짜입니다