MySQLdb always return a long and hex append 'L' when converting long so long must be converted into int before calling hex.