Python 解码 AMF 响应

标签 python amf

我在 python 中向返回 AMF 的 Web 服务发出请求。我还不知道它是 AMF0 还是 AMF3。

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

( Full data here )

如何获取 r.text 并将其转换为 python 对象或类似对象?我找到了 amfast但它的 Decoder 类返回一个 3.131513074181806e-294 假设 AMF0 和 None 为 AMF3。 (均不正确)

from amfast.decoder import Decoder
decoder = Decoder(amf3=False)
obj = decoder.decode(StringIO.StringIO(r.text))

最佳答案

我看到您的代码有两个问题,第一个是使用 r.text 返回二进制数据。请改用 r.content。第二个问题是使用decoder.decode 方法,它解码一个对象而不是数据包。请改用 decoder.decode_packet

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

使用 Pyamf 也可以,使用 r.content

关于Python 解码 AMF 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13774443/

相关文章:

python - 将图像分成 block

python - Scrapy:将 response.body 保存为 html 文件?

python 相当于 std::chrono::steady_clock::now();

安卓AMF协议(protocol)

python - PhantomJS - 连接到 GhostDriver 错误

python - 使用 Python 解析大型 .csv 文件行

java - 在可能被序列化的类上使用字节码增强技术是否安全,为什么?

java - Java 中字节数组到 29 位整数的最快且最有效的转换

python - python3 的 AMF 序列化

actionscript-3 - 在 AS3 的子类中序列化向量时遇到问题