如何从 table 中获取所有列并使用 python 将其作为 csv 文件保存在 s3 中

How to fetch all columns from table and save it in s3 as csv file using python

cur = con.cursor()
for i in sample:
    cur.execute("select `count(*)`,cricking_duels_ratings,cast(`sysdate()` as CHAR) from {}".format(i))
    res = cur.fetchall()
    for row in res:
        print(row)
    ob = s3.Object(BUCKET_NAME, '/testing.csv')
    ob.put(Body=row)
    print("done")

当我尝试上述操作时,出现以下错误

'invalid type of parameter body..type: , valid types: , , file-like object'

有什么建议请..

创建本地文件,然后使用 upload_file() 将文件复制到 S3 通常更容易。这也使得调试更容易,因为您可以查看本地文件的内容以确保它已正确转换为 CSV。

我怀疑您的问题与将 row 转换为包含逗号分隔值的字符串有关。参见:How to Iterate through cur.fetchall() in Python