V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
wersonliu9527
V2EX  ›  Python

如何解析别人接口中返回的 protobuf 呢

  •  
  •   wersonliu9527 · Dec 4, 2019 · 7224 views
    This topic created in 2340 days ago, the information mentioned may be changed or developed.

    2019-12-04 16-02-21 的屏幕截图.png

    通过 charles 抓包,接口返回 protobuf.通过 requests 构造这个请求,返回啥都没有但状态吗 200. 可能有老哥看到这个结构就知道我在爬哪个了.看破不说破哈 0.0

    8 replies    2019-12-05 10:42:45 +08:00
    dreamerlv3ex
        1
    dreamerlv3ex  
       Dec 4, 2019
    看不懂
    wersonliu9527
        2
    wersonliu9527  
    OP
       Dec 4, 2019
    @dreamerlv3ex 一般接口返回都是 json 数据,但是这个接口返回的是 protobuf,不知道怎么解析
    keepeye
        3
    keepeye  
       Dec 4, 2019   ❤️ 1
    这不就是 protoc --decode_raw 结果吗

    大部分情况下也足够了,如果要知道每个字段含义,那必须得有 protobuf 定义文件才行

    你抓的是 vx?
    wersonliu9527
        4
    wersonliu9527  
    OP
       Dec 4, 2019
    @keepeye 不是 vx, 这个老版本是 json,新版本是 protobuf.理论上能够对着老版本 json 结构把这个.proto 文件定义好吧? 但是再怎么解析呢, requests 脚本 content,text 都是空
    keepeye
        5
    keepeye  
       Dec 4, 2019
    @wersonliu9527 你可以把二进制 16 进制字符串拷出来,然后参考 json 定义 protobuf 消息(字段不用全定义),写个脚本解析一下试试
    nxy006
        6
    nxy006  
       Dec 5, 2019
    必须要有 protobuf 的定义(.proto 文件),再把这个问题编译成类( Java、Python、C++等都支持)。以 Java 为例,调用 GenClass.parseFrom(response.toByteArray()); 方法就可以获得结果的实例,具体参数的值可以调 get 方法获得。
    sanget
        7
    sanget  
       Dec 5, 2019
    protobuf 是加密过的,没有原 .proto 文件基本翻译不出来。
    locoz
        8
    locoz  
       Dec 5, 2019
    翻源码找到它的 protobuf 解析部分( proto 文件转换的对应语言的代码)然后照着定义成 proto 文件再转回 python 版本
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1084 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 23:51 · PVG 07:51 · LAX 16:51 · JFK 19:51
    ♥ Do have faith in what you're doing.