user3344239 user3344239 - 2 months ago 13
MySQL Question

unable to insert string or read-only buffer, not long

I tried to venture off while following a python-flask tutorial and am having trouble figuring out an error. I tried browsing stack for 6 hours off and on and nothing out there related could help me out, possibly because I am a beginner...

I gathered data from a form (all the data is passing through fine, I tested by printing to the console) and want to insert it into a mysql table.

Here is the query code:

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)))


The table description in MySql is:

+------------------+-------------+------+-----+---------+----------------+
| 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 | |
+------------------+-------------+------+-----+---------+----------------+


The error I keep getting is:
must be string or read-only buffer, not long


I don't see where the long is coming from...Not sure what else you may need to help me out so ask if there's more info I can add.

much appreciated!

Answer

Check all the variables type which are being inserted.

I would guess one of them is suppose to be text or varchar, but is a long.

Try converting the long to a str basically one of the numbers being inserted isnt text but might look like 37582L

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

if type(some_long) is long:
    do_insert(str(some_long))
Comments