I have a MySQL table where a field have a type of INT. In my Python script I am reading the hexadecimal value (0xc558, for example) and trying to insert this value in the table as INT field type.
Doing so gives me:
(1265, "Data truncated for column at row 1)
An INT field type should be a standard integer with 4 bytes which should accept the value of 0xC558, which is 50520 in a decimal world.
I'm not doing any conversion, and the code I use is:
self.cur.execute("INSERT INTO my_table VALUES(NULL, %s)", (dataDict["hex_value"],)
where dataDict["hex_value"] is 0xC558.
Trying to use int(dataDict["hex_value"]) also gives an error: Invalid literal for int() with base 10: 0xC558.
Trying to use int(dataDict["hex_value"],base=16) also gives an error: int() can't convert non-string with explicit base.
EDIT: the value is of type 'str', as print type(dataDict["hex_value"]) shows (type 'str')
typeisdataDict['hex_value']?print(dataDict['hex_value'])repr(dataDict['hex_value'])give you?strI wonder why on earth you get the exception when you do:int(dataDict["hex_value"],base=16)X'C558', not0xC558. So it's treating that value as a string, not a hex number. I suggest you convert it to an integer in Python before doing theINSERT.