[英]Why is my python script hanging when I try to capture/upload a picture?
Trying to upload photos from a Raspberry Pi to AWS S3, but have encountered a couple of errors. 尝试将照片从Raspberry Pi上传到AWS S3,但遇到了两个错误。 Program will hang on uploading the picture to AWS.
程序将挂起,将图片上传到AWS。
Tried moving it to a separate script and calling it within the program, and putting it as the beginning line of the program. 尝试将其移动到单独的脚本中并在程序中调用,并将其作为程序的开始行。 Each resulted in the program hanging at upload.
每个都导致程序在上载时挂起。 When the script is ran on its own, it will work.
当脚本独自运行时,它将起作用。
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 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()
Expect the picture to be uploaded and have the "after upload" statement printed out. 期望图片被上传并打印出“上传后”声明。 So far only the "before capture statement is printed at, and then the program will hang when trying to u
到目前为止,仅打印“捕获前的语句”,然后在尝试使用该程序时该程序将挂起
To create a client in boto3
, use: 要在
boto3
创建客户端,请使用:
import boto3
client = boto3.client(
's3',
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.