使用 python 从 MSSQL 读取 uniqueidentifier 字段
我使用 pyodbc 访问我的 MSSQL 数据库。
当从 MSSQL 读取 uniqueidentifier 字段时,在我的 MacOS 中,我可以打印 udid 字段的正确值(例如 4C444660-6003-13CE-CBD5-8478B3C9C984),但是当我在 Linux CentOS 上运行相同的代码时,我只看到非常奇怪的字符串像“???E??6??????c”,值的类型是“buffer”,而不是MacOS中的“str”。
你能解释一下为什么会这样吗?我怎样才能在Linux上获得正确的uidi值?谢谢
I used pyodbc to access my MSSQL database.
When reading uniqueidentifier field from MSSQL, in my MacOS, I can print the correct value of udid field (e.g 4C444660-6003-13CE-CBD5-8478B3C9C984), however when I run the same code on Linux CentOS, i just see very strange string like "???E??6??????c", and the type of value is "buffer", not "str" as in MacOS.
Could you explain me why it is and how can i get correct value of uidi on linux? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在linux中,我使用str(uuid.UUID(bytes_le=value)).upper()来获取像4C444660-6003-13CE-CBD5-8478B3C9C984这样的uniqueidentifier字段的字符串
In linux i use str(uuid.UUID(bytes_le=value)).upper() to get string like 4C444660-6003-13CE-CBD5-8478B3C9C984 of uniqueidentifier field
这已经有几年了,但我最近不得不解决同样的问题。我的解决方案是简单地将唯一标识符转换为 VARCHAR,这使我的 Python 代码保持整洁:
然后在 Python 中,只需输出 row.my_id。
This is a few years old, but I've had to tackle this same problem recently. My solution was to simply CAST the unique identifier as a VARCHAR, which kept my Python code nice and tidy:
Then in Python, simply output row.my_id.