使用pypyodbc 1.3.4的Python中的字节字符串过长错误 [英] byte string too long error in Python using pypyodbc 1.3.4

查看:189
本文介绍了使用pypyodbc 1.3.4的Python中的字节字符串过长错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用pypyodbc 1.3.4和Python Anaconda 3.5的Unix环境中保存超过127个字符时,出现字节字符串太长的错误.

通过此链接字节字符串太长PyPyOdbc 并按照说明进行了修复但问题仍然存在.

Gone through this link Byte string too long PyPyOdbc and applied the fix as stated but still issue persists.

我正在尝试保存超过127个字符.数据库是MS Sql Server.列类型是varchar MAX或nvarchar MAX(我都尝试过).

I am trying to save more than 127 characters. Database is MS Sql Server. Column type is varchar MAX or nvarchar MAX (I tried with both).

保存127个字符或少于127个字符可以正常工作.

Saving 127 orless than 127 characters is fine and working.

谢谢

推荐答案

我在MS SQL和pypyodbc 1.3.4上遇到了NVARCHAR(MAX)的相同问题:

I ran into the same issue with NVARCHAR(MAX) on MS SQL and pypyodbc 1.3.4:

    cursor.execute("insert into mytable (my_nvarchar_max_column) values (?)", "some long text here......")

出现字节字符串太长"错误.

fails with 'byte string too long' error.

将字符串作为字节数组传递是可行的:

Passing the string as a byte array works:

cursor.execute("insert into mytable (my_nvarchar_max_column) values (?)", 
"some long text here......".encode('utf8'))

这篇关于使用pypyodbc 1.3.4的Python中的字节字符串过长错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆