InterfaceError:执行操作失败; Python 类型 numpy.int64 无法转换

Posted

技术标签:

【中文标题】InterfaceError:执行操作失败; Python 类型 numpy.int64 无法转换【英文标题】:InterfaceError: Failed executing the operation; Python type numpy.int64 cannot be converted 【发布时间】:2019-11-05 22:24:51 【问题描述】:

我不知道问题出在哪里!有人可以帮助我吗?

cnx=mysql.connector.connect(user='root',password='suraj1697',host='127.0.0.1',database='model') mycursor=cnx.cursor() sql="INSERT INTO model2 (length,host_length,path_length,fd_length,tld_length,count1,count2,count3,count4,count5,count6,count_http,count_https,count_www,count_digit,count_letter,count_dir,count_ip,count_short) 值(%d, %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ,%d)" 打印(sql) 数据=[] for i in range(1, 32):

mycursor.execute('创建数据库模型')

mycursor.execute("ALTER TABLE model2(id INT AUTO_INCREMENT PRIMARY KEY,lenght INT,host_length INT,path_length INT,fd_length INT,tld_length INT,count1 INT,count2 INT,count3 INT,count4 INT,count5 INT,count6 INT,count_http INT,count_https INT,count_www INT,count_digit INT,count_letter INT,count_dir INT,count_ip INT,count_short INT)")
#record=[int(urldata['url_length'][i]),int(urldata['hostname_length'][i]),int(urldata['path_length'][i]),int(urldata['fd_length'][i]),int(urldata['tld_length'][i]),int(urldata['count-'][i]),int(urldata['count@'][i]),int(urldata['count?'][i]),int(urldata['count%'][i]),int(urldata['count.'][i]),int(urldata['count='][i]),int(urldata['count-http'][i]),int(urldata['count-https'][i]),int(urldata['count-www'][i]),int(urldata['count-digits'][i]),int(urldata['count-letters'][i]),int(urldata['count_dir'][i]),int(urldata['use_of_ip'][i]),int(urldata['short_url'][i])]
record=[urldata['url_length'][i],urldata['hostname_length'][i], urldata['path_length'][i], urldata['fd_length'][i], urldata['tld_length'][i], urldata['count-'][i],urldata['count@'][i], urldata['count?'][i], urldata['count%'][i], urldata['count.'][i], urldata['count='][i], urldata['count-http'][i], urldata['count-https'][i],urldata['count-www'][i], urldata['count-digits'][i], urldata['count-letters'][i],urldata['count_dir'][i], urldata['use_of_ip'][i], urldata['short_url'][i]]
data.append(record)

打印(数据) mycursor.executemany(sql,数据) cnx.commit()

【问题讨论】:

【参考方案1】:

您的输入数据之一是 numpy.int6 类型。简单的解决方案是将值封装在 int() 中。正确的方法是使用numpy提供的astype()方法。

例如:

变量.astype(int)

【讨论】:

以上是关于InterfaceError:执行操作失败; Python 类型 numpy.int64 无法转换的主要内容,如果未能解决你的问题,请参考以下文章

pymysql.err.InterfaceError: (0, '')解决办法

InterfaceError:错误绑定参数5 ... Django JWT令牌(django请求令牌工具)

asyncpg - 无法执行操作:另一个操作正在进行中

长时间运行的 py.test 在第一次失败时停止

InterfaceError: Error binding Parameter 5...Django JWT token (django request token tool)

接口错误(0,'')