Hi there,
First time user here so not entirely sure this is the most appropriate place to ask - apologies if not but I've seen some similar posts here.
I have a python script that connects to a camera and takes a snapshot, it then stores the image in an S3 bucket.
For some reason the images are downloading with a grey bar on the bottom, suggesting that the image doesn't fully download(?). The reason I suspect this is that I have a second camera where the script works perfectly fine.
Here's the script
# Configure logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
def lambda_handler(event, context):
# Camera details
ip = "1.1.1.1"
port = "1234"
user = "user"
password = "password"
url = f"http://{ip}:{port}/cgi-bin/snapshot.cgi?1"
# AWS S3 details
bucket_name = 'my-bucket'
# Initialize S3 client
s3_client = boto3.client('s3')
# Make a GET request to the camera with Digest Authentication
try:
logger.debug("Making a GET request to the camera with Digest Authentication")
response = requests.get(url, auth=HTTPDigestAuth(user, password))
except Exception as e:
logger.error(f"Error making GET request: {e}")
return f"Error making GET request: {e}"
# Check if the request was successful
if response.status_code == 200:
logger.debug("Successfully received response from camera")
# Create a filename with the current date and time
filename = datetime.now().strftime("%Y%m%d_%H%M%S") + ".JPG"
logger.debug(f"Generated filename: {filename}")
# Upload the image to S3
try:
logger.debug("Uploading image to S3")
s3_client.put_object(Bucket=bucket_name, Key=filename, Body=response.content)
logger.debug(f"Snapshot uploaded as {filename} to S3 bucket {bucket_name}")
return f"Snapshot uploaded as {filename} to S3 bucket {bucket_name}"
except Exception as e:
logger.error(f"Error uploading to S3: {e}")
return f"Error uploading to S3: {e}"
else:
logger.error(f"Failed to get snapshot: HTTP {response.status_code}")
return f"Failed to get snapshot: HTTP {response.status_code}"
Any ideas / help would be greatly appreciated!