通过AWS Cloudwatch Syntetic Canary函数通过身份验证获取URL

2024-05-15 21:46:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我们使用AWS Cloudwatch Syntetic Canary通过发送GET请求来测试应用程序URL的可用性。 现在,我想监视一个URL,但这个URL需要一个密钥ID进行身份验证,才能得到200个响应。 以下是对URL的简单get请求,无需验证:

from aws_synthetics.selenium import synthetics_webdriver as syn_webdriver

from aws_synthetics.common import synthetics_logger as logger


    def main():
    
        url = "http://google.com"
   
        # Set screenshot option
        takeScreenshot = True
        browser = syn_webdriver.Chrome()
    
        browser.get(url)
    
        if takeScreenshot:
            browser.save_screenshot("loaded.png")  
        response_code = syn_webdriver.get_http_response(url)
        if not response_code or response_code < 200 or response_code > 299:
            raise Exception("Failed to load page!")
    
        logger.info("Canary successfully executed")
 
    def handler(event, context):
  
        # user defined log statements using synthetics_logger
        logger.info("Selenium Python heartbeat canary")
        return main()

如何使用python Selenium发出Get请求并提供用于身份验证的密钥? 多谢各位


Tags: frombrowser身份验证awsurlgetresponse密钥