简体   繁体   中英

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

when I try the above, i'm getting following error

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

any suggestions please..

It is normally easier to create a local file, then use upload_file() to copy the file to S3. This also makes it easier to debug, since you can view the content of the local file to ensure that it was correctly converted to CSV.

I suspect your problem has to do with converting the row into a string containing comma-separated values. See: How to Iterate through cur.fetchall() in Python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM