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
eunha
V2EX  ›  Python

Python 如何向服务端提交 pickle.dumps 产生的 bytes(要保真)?

  •  
  •   eunha · Mar 31, 2019 · 1926 views
    This topic created in 2594 days ago, the information mentioned may be changed or developed.

    服务端收到时 bytes 变成了字符串,而且有乱码,还原不回去了 pickle.dumps 返回的 bytes,不知道其使用了什么编码,如 pickle.dumps({})会返回 b'\x80\x03}q\x00.'

    这样的数据,用 utf-8 解码无法解码: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

    而用 utf-16 解码则不可逆: in: b out: b'\x80\x03}q\x00.' in: b.decode(encoding='utf-16').encode(encoding='utf-16') out: b'\xff\xfe\x80\x03}q\x00.'

    求可逆的这种 bytes 转换为 str 的方法,如果能获取 post 的原始数据就更感激不尽了

    forestLittleBear
        1
    forestLittleBear  
       Mar 31, 2019 via Android
    流弊。
    不知道使用什么编码可还行。。。
    不知道编码格式怎么解码。。。?
    lolizeppelin
        2
    lolizeppelin  
       Apr 1, 2019
    用 struct 谢谢
    pickle 是 python 自己用的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1186 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 23:14 · PVG 07:14 · LAX 16:14 · JFK 19:14
    ♥ Do have faith in what you're doing.