无法插入字符串或只读缓冲区,不长

时间:2016-09-26 06:18:09

标签: python mysql

我尝试冒险,同时遵循python-flask教程并且无法找出错误。我试着连续6个小时浏览堆栈,没有相关内容可以帮助我,可能是因为我是初学者......

我从表单中收集数据(所有数据都经过精细处理,我通过打印到控制台进行测试)并希望将其插入到mysql表中。

以下是查询代码:

c.execute("INSERT INTO posts (post_count, seller, title, id, bus, condition, transType, post_description, trade, price) VALUES (%i, %s, %s, %s, %s, %s, %s, %s, %s, %i)", (thwart(postCount), thwart(seller), thwart(title), thwart(id), thwart(bus), thwart(condition), thwart(transType), thwart(description), thwart(tradeFor), thwart(price)))

MySql中的表描述是:

+------------------+-------------+------+-----+---------+----------------+
| Field            | Type        | Null | Key | Default | Extra          |
+------------------+-------------+------+-----+---------+----------------+
| post_id          | int(11)     | NO   | PRI | NULL    | auto_increment |
| post_count       | int(11)     | YES  |     | NULL    |                |
| seller           | varchar(60) | YES  |     | NULL    |                |
| title            | text        | YES  |     | NULL    |                |
| id               | varchar(25) | YES  |     | NULL    |                |
| bus              | varchar(35) | YES  |     | NULL    |                |
| condition        | varchar(20) | YES  |     | NULL    |                |
| transType        | varchar(25) | YES  |     | NULL    |                |
| post_description | text        | YES  |     | NULL    |                |
| trade            | text        | YES  |     | NULL    |                |
| price            | int(11)     | YES  |     | NULL    |                |
+------------------+-------------+------+-----+---------+----------------+

我一直遇到的错误是:must be string or read-only buffer, not long

我不知道漫长的来自哪里......不确定你还需要什么来帮助我,所以问一下我是否可以添加更多信息。

非常感谢!

1 个答案:

答案 0 :(得分:0)

检查正在插入的所有变量type

我猜其中一个假设是text或varchar,但是long

尝试将long转换为str基本上插入的数字中的一个不是文本,但可能看起来像37582L

print(type(post_count))
print(type(seller))
print(type(post_description))

if type(some_long) is long:
    do_insert(str(some_long))
相关问题