gpt4 book ai didi

Python Lambda 检查 URL 健康状况

转载 作者:行者123 更新时间:2023-12-01 00:21:44 26 4
gpt4 key购买 nike

我写了一个小函数,但是当我执行它时,只有列表中的最后一个 URL 被传递给函数。请纠正我

def lambda_handler(event, context):
websiteURL = ['https://example1.com','https://example2.com','https://example3.com']
topicArnCode = 'arn:aws:sns:ap-southeast-1:123:sample'
for x in websiteURL:
print (x)
r = requests.get(x,verify=False)
print (r)
if r.status_code == 200:
return 'Website is alive!'
else:
sns_client = boto3.client('sns')
sns_client.publish(
TopicArn = topicArnCode,
Subject = 'Website is not reachable ' + x,
Message = 'Website: ' + x + ' is down\n')
return 'Website is dead'

最佳答案

这是一个缩进拼写错误:

def lambda_handler(event, context):
websiteURL = ['https://example1.com','https://example2.com','https://example3.com']
topicArnCode = 'arn:aws:sns:ap-southeast-1:123:sample'
for x in websiteURL:
print (x)
r = requests.get(x,verify=False)
print (r)
if r.status_code == 200:
print('Website is alive!')
else:
sns_client = boto3.client('sns')
sns_client.publish(
TopicArn = topicArnCode,
Subject = 'Website is not reachable ' + x,
Message = 'Website: ' + x + ' is down\n')
print('Website is dead')

关于Python Lambda 检查 URL 健康状况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58908092/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com