尝试将照片从Raspberry Pi上传到AWS S3,但是遇到了两个错误。程序将挂起,将图片上传到AWS。
试图将其移动到单独的脚本中并在程序中调用,并将其作为程序的开始行。每个都导致程序在上载时挂起。当脚本单独运行时,它将起作用。
import ssl
import time
import json
import gpiozero
import boto3
import picamera
import pic
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTShadowClient
def main():
pic.capture('pi.png')
myShadowClient = AWSIoTMQTTShadowClient(CLIENT ID)
myShadowClient.configureEndpoint(ENDPOINT, PORT NUMBER)
myShadowClient.configureCredentials(ROOT CA,/PRIVATE KEY ,CERTIFICATION)
myDeviceShadow = myShadowClient.createShadowHandlerWithName("ThingName", True)
myShadowClient.configureConnectDisconnectTimeout(10) # 10 sec
myShadowClient.configureMQTTOperationTimeout(5) # 5 sec
myShadowClient.connect(1200) #Print this out on
#s3.upload_file('pipic.png',bucket_name,'pipic.png')
#s3.upload_file('test5.png',bucket_name,'test5.png')
while True:
myDeviceShadow.shadowGet(customShadowCallback_Update, 5)
time.sleep(5)
pic.py
import picamera
import boto3
camera = picamera.PiCamera()
def capture(filename):
camera.capture(filename)
s3 = boto3.client(CLIENTID, ACCESS KEY ID, SECRET ACCESS KEY)
bucket_name = ''
for y in range(20):
print("before capture")
capture(str(y)+'pi.png')
s3.upload_file(str(y)+'pi.png',bucket_name, str(y)+'pi.png')
print("after upload")
camera.close()
期待要上传的图片,并打印出“上传后”声明。到目前为止,仅打印“捕获前的语句”,然后在尝试执行u
时程序将挂起。答案 0 :(得分:0)
要在boto3
中创建客户端,请使用:
import boto3
client = boto3.client(
's3',
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY
)