![](/img/trans.png)
[英]import-im6.q16: not authorized error 'os' @ error/constitue.c/WriteImage/1037 for a Python web scraper
[英]import-im6.q16: not authorized `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')
]
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')'
您的脚本缺少顶部的shebang行#!/usr/bin/env python3
。 因此,您的脚本是由bash
shell运行的,而不是由Python解释器运行的。 bash
不理解Python代码,因此会出现错误。
将shebang行添加到脚本的顶部,然后重试。
如果不是从许可的ec2实例运行此代码,则需要适当配置凭据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.