[英]Python decode AMF response
I'm making a request in python to a web service which returns AMF. 我在python中向一个返回AMF的Web服务发出请求。 I don't know if it's AMF0 or AMF3 yet. 我不知道它是AMF0还是AMF3。
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? 如何获取r.text
并将其转换为python对象或类似对象? I found amfast but it's Decoder
class returns a 3.131513074181806e-294
assuming AMF0 and None
for AMF3. 我发现amfast但它的Decoder
类返回3.131513074181806e-294
假设AMF0为AMF0而None
。 (Both incorrect) (两者都不正确)
from amfast.decoder import Decoder
decoder = Decoder(amf3=False)
obj = decoder.decode(StringIO.StringIO(r.text))
have u tried PyAMF. 你试过PyAMF吗?
from pyamf import remoting
remoting.decode(data)
I see two problems with your code, the first is using r.text
to return binary data. 我看到你的代码有两个问题,第一个是使用r.text
来返回二进制数据。 Use r.content
instead. 请改用r.content
。 The second problem is using decoder.decode
method, which decodes one object and not a packet. 第二个问题是使用decoder.decode
方法,它解码一个对象而不是数据包。 Use decoder.decode_packet
instead. 请改用decoder.decode_packet
。
from amfast.decoder import Decoder
decoder = Decoder(amf3=True)
obj = decoder.decode_packet(r.content)
Using Pyamf works as well, using r.content
. 使用Pyamf也可以使用r.content
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.