문제

I'm making a request in python to a web service which returns AMF. I don't know if it's AMF0 or AMF3 yet.

r = requests.post(url, data=data)
>>> r.text
u'\x00\x03...'

(Full data here)

How can I take r.text and convert it to a python object or similar? I found amfast but it's Decoder class returns a 3.131513074181806e-294 assuming AMF0 and None for AMF3. (Both incorrect)

from amfast.decoder import Decoder
decoder = Decoder(amf3=False)
obj = decoder.decode(StringIO.StringIO(r.text))
도움이 되었습니까?

해결책

I see two problems with your code, the first is using r.text to return binary data. Use r.content instead. The second problem is using decoder.decode method, which decodes one object and not a packet. Use decoder.decode_packet instead.

from amfast.decoder import Decoder
decoder = Decoder(amf3=True)
obj = decoder.decode_packet(r.content)

Using Pyamf works as well, using r.content.

다른 팁

have u tried PyAMF.

from pyamf import remoting
remoting.decode(data)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top