相关疑难解决方法(0)

TypeError:'int'对象不可迭代 - Python

我收到以下错误:

  File "/home/ec2-user/test/test_stats.py", line 43, in get_test_ids_for_id
    cursor.execute("""select test_id from test_logs where id = %s """, (id))
  File "/home/ec2-user/.etl/lib/python2.7/site-packages/MySQLdb/cursors.py", line 187, in execute
    query = query % tuple([db.literal(item) for item in args])
TypeError: 'int' object is not iterable
Run Code Online (Sandbox Code Playgroud)

这是我的代码部分,我遇到了麻烦:

def get_test_ids_for_id(prod_mysql_conn, id):
    cursor = prod_mysql_conn.cursor()
    cursor.execute("""select test_id from test_logs where id = %s """, (id))
    rows = cursor.fetchall()
    test_ids = []
    for row in rows:
      test_ids.append(row[0])
    return test_ids
Run Code Online (Sandbox Code Playgroud)

python mysql mysql-python python-2.7

5
推荐指数
1
解决办法
7930
查看次数

标签 统计

mysql ×1

mysql-python ×1

python ×1

python-2.7 ×1