如何使用AWS ec2上的jupyter笔记本对Googlesheet进行API调用

2024-04-20 12:32:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我在亚马逊SageMaker上把它当作一个jupyter笔记本来运行。

-

  • 因此,我创建了一个S3 Bucket并将json文件(googlesheet凭证)存储在其中。你知道吗
  • 我使用Boto3,我能够将凭证拖到Jupyter笔记本上。你知道吗

  • 现在尝试打开creds = ServiceAccountCredentials.from_json_keyfile_name(result, scope)

#它给出错误,预期的字符串不是听写的


# Create an S3 client
s3 = boto3.client('s3')


# Call to S3 to retrieve the policy for the given bucket
result = s3.get_bucket_acl(Bucket='sheet-credentials')
print(result)


# Calling google sheet api

creds = ServiceAccountCredentials.from_json_keyfile_name(result, scope)
client = gspread.authorize(creds)

sheet = client.open("CALCULATOR").worksheet("hist")
google_sheet = sheet.get_all_records()

print(google_sheet)

FileNotFoundError: [Errno 2] No such file or directory: 'sheet-credential.json' 

它在我的本地机器上工作,因为我在本地有sheet-credential.json文件。你知道吗

如何将此文件发送到EC2实例以运行脚本?你知道吗


Tags: 文件namefromclientjsons3bucketgoogle