1
我試圖在遵循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
我看不到的地方很長時間來自...不知道你可能需要幫助我什麼,所以問是否有更多的信息我可以添加。
非常感謝!
檢查'type'正在被插入的所有變量。我猜想其中的一個假設是「text」或「varchar」,但是是「long」。嘗試將'long'轉換爲'str'基本上其中一個插入的數字不是文本,但可能看起來像'37582L' – jmunsch
請參閱:http://stackoverflow.com/questions/2104884/how-does-python-manage- int-and-long – jmunsch
我只是嘗試投射每一個變種,但它沒有奏效。謝謝你的想法,儘管... @ jmunsch – user3344239