python - import-im6.q16: 未授权“boto3”@error/constitute.c/WriteImage/1037
问题描述
我使用 AWS CLI 。我安装了 boto3 并尝试运行该代码。我有三个错误
import boto3
s3 = boto3.resource('s3')
# Get list of objects for indexing
images=[('afridi.jpg','Shahid Afridi'),
('sakib.jpg','Sakib Al Hasan'),
('kohli.jpg','Birat Kohli'),
('masrafi.jpg','Mashrafe Bin Mortaza'),
('ganguli.jpg','Sourav Ganguly')
]
遍历列表以将对象上传到 S3
for image in images:
file = open(image[0],'rb')
object = s3.Object('taifur12345bucket',image[0])
ret = object.put(Body=file,
Metadata={'FullName':image[1]}
)
错误
import-im6.q16: not authorized `boto3' @ error/constitute.c/WriteImage/1037.
./code1.py: line 2: syntax error near unexpected token `('
./code1.py: line 2: `s3 = boto3.resource('s3')'
解决方案
您的脚本缺少#!/usr/bin/env python3
顶部的 shebang 行。因此,您的脚本由bash
shell 运行,而不是由 Python 解释器运行。 bash
不理解 Python 代码,因此会出现错误。
将 shebang 行添加到脚本的顶部,然后重试。
推荐阅读
- vue.js - 无法在不重置分页的情况下刷新 b-table 组件?
- python - 如何到达有障碍物的终点
- git - git 分叉是如何工作的?
- android - 我如何解决它?错误:命令失败:gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
- c# - 自动递增列(DataGridView、Microsoft Access)
- tensorflow - Colab kill '^C' - 小数据集和小批量大小的内存不足?
- java - Spring Cloud Gateway 中请求参数的账号
- javascript - 如何使用此数据将两个数组合二为一?JS
- postgresql - 如果我已经在进行交易,我还需要 SELECT FOR UPDATE() 吗?
- google-fit - Google Fit App 未显示使用 Rest API 上传的锻炼路径