python 3.2 mysql模块'int' does not support the buffer interface问题的解决

作者:小鱼的互联网观察 发布时间:January 10, 2013 分类:技术

写了个python爬虫,网络方面性能很好,爬到的数据写入数据库中。

 

但是问题来了,写入了大概2w行之后报错。错误内容是:

 

'int' does not support the buffer interface 

问题出现在int的一个转换问题。解决办法如下:

修改Python32\site-packages\pymysql\connections.py 文件中的

unpack_int24
unpack_int32
unpack_int64

三个函数。修改成下面样子

def unpack_int24(n):
    try:
        return struct.unpack('B',n[0])[0] + (struct.unpack('B', n[1])[0] << 8) +\
            (struct.unpack('B',n[2])[0] << 16)
    except TypeError:
        return n[0]+(n[1]<<8)+(n[2]<<16)

def unpack_int32(n):
    try:
        return struct.unpack('B',n[0])[0] + (struct.unpack('B', n[1])[0] << 8) +\
            (struct.unpack('B',n[2])[0] << 16) + (struct.unpack('B', n[3])[0] << 24)
    except TypeError:
        return n[0]+(n[1]<<8)+(n[2]<<16)+(n[3]<<24)

def unpack_int64(n):
    try:
        return struct.unpack('B',n[0])[0] + (struct.unpack('B', n[1])[0]<<8) +\
        (struct.unpack('B',n[2])[0] << 16) + (struct.unpack('B',n[3])[0]<<24)+\
        (struct.unpack('B',n[4])[0] << 32) + (struct.unpack('B',n[5])[0]<<40)+\
        (struct.unpack('B',n[6])[0] << 48) + (struct.unpack('B',n[7])[0]<<56)
    except TypeError:
        return n[0]+(n[1]<<8)+(n[2]<<16)+(n[3]<<24) \
              +(n[4]<<32)+(n[5]<<40)+(n[6]<<48)+(n[7]<<56)

修改 完成后保存。好了,问题解决了。。

标签: 'int' does not support the buffer interface, python 3.2 mysql

互联网观察
python 3.2 mysql模块'int' does not support the buffer interface问题的解决
本文地址:http://tianmeng.org/archives/281/

相关文章

  • 无相关文章
文档信息

当前暂无评论 »

网站地图 京ICP证030173号