简体   繁体   English

尝试捕获/上传图片时,为什么python脚本挂起?

[英]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.

相关问题 为什么http请求挂在我的python脚本中? - Why is the http request hanging in my python script? 尝试进行API调用时,为什么我的python脚本停止执行? - Why does my python script stop executing when I try to make my API call? 尝试通过解释器运行Python脚本时,为什么会出现“ ImportError:未命名模块”的提示? - Why do I get “ImportError: No module named” when I try to run my Python script via the Interpreter? 我无法弄清楚为什么我的 python 脚本可以运行,但是当尝试使其成为可执行文件时它不起作用 - I can't figure out why my python script works but when try to make it an executable it does not work 当我尝试通过将命令添加到 /etc/profile 来在 Raspberry Pi 启动时执行它时,为什么我的 Python 脚本在后台运行两次? - Why is my Python script running twice in the background when I try to execute it at startup of my Raspberry Pi by adding the command to /etc/profile? 我怎么知道我的python脚本挂在哪里? - How can I tell where my python script is hanging? 为什么在尝试附加Python时我的列表没有加入 - Why my lists are not Joining When I try to Append Them Python 为什么当我尝试在 kattis 上上传此 Python 代码时会出现运行时错误? - Why does this Python code give a runtime error when I try to upload it on kattis? Python脚本在后台运行时挂起 - Python script hanging when running in the background 当我尝试在python脚本中访问此JSON文件的第一项时,为什么会收到KeyError? - Why do I get a KeyError when I try to access the first item of this JSON file in a python script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM