V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
fxxkgw
V2EX  ›  Python

Python 如何处理 mysql 的 varbinary 类型

  •  
  •   fxxkgw · 2020-04-23 18:53:57 +08:00 · 1402 次点击
    这是一个创建于 1480 天前的主题,其中的信息可能已经有所发展或是发生改变。

    数据库准备存储 ipv6 地址,设置的类型为 varbinary ( 16 )
    在 mysql 的终端可以通过 INET6_ATON (“ipv6”)方法将字符串类型的 ipv6 地址插入数据库 ,然后可以通过 INET6_NTOA ()方法把 varbinary 类型的 ipv6 地址转化为字符串类型。

    现在我在终端通过 insert into table(ip) values(INET6_ATON('fdfe::5a55:caff:fefa:9089'));方法插入了一条 ipv6 地址,通过 python 的 mysql 处理模块,拿到的返回值是:\xfd\xfe\x00\x00\x00\x00\x00\x00ZU\xca\xff\xfe\xfa\x90\x89

    如何将这条数据转为为可读性更好的 fdfe::5a55:caff:fefa:9089 这种字符串呢?用什么库或者方法实现呢?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1939 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:18 · PVG 00:18 · LAX 09:18 · JFK 12:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.