I want to PUT the csv file in S3 in the requests module.

Asked 1 years ago, Updated 1 years ago, 302 views

I am thinking of using Python requests module to PUT the csv file stored in AWS S3 (the file contains Japanese and needs to be converted from utf8 to Shift_jis).
Please let me know what kind of code I should write for this process.

python csv amazon-s3 python-requests

2023-01-17 16:39

1 Answers

import requests
import pandas aspd

# Retrieve csv file from S3
url="https://s3.amazonaws.com/your-bucket-name/your-file.csv"
r=requests.get(url)

# Convert to Shift_jis
df=pd.read_csv(r.content, encoding='utf-8')
df.to_csv("your-file.csv", index=False, encoding='shift_jis')

# PUT to SharePoint site
url="https://your-tenant.sharepoint.com/sites/your-site/_api/web/lists(guid'your-list-guid')/items(your-item-id)/AttachmentFiles/add(FileName='your-file.csv')"
headers = {
    "Accept": "application/json;odata=verbose",
    "Content-Type": "application/octet-stream",
    "Authorization": "Bearer" + access_token
}
with open("your-file.csv", "rb") as f:


2023-01-17 21:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.