【问题标题】:Trigger DAG from google cloud function从谷歌云函数触发 DAG
【发布时间】:2020-04-19 11:08:45
【问题描述】:

当文件到达基于云composer documentation 的 GCS 存储桶时,我一直在尝试在 Cloud Composer (composer-1.8.1-airflow-1.10.3) 中执行 DAG Python 中的云函数

我一直没能让它工作,每次触发,函数都会返回这个消息到日志中

Exception: Bad response from application: 400 / {'Date': 'Mon, 30 Dec 2019 18:07:02 GMT', 'Content-Type': 'text/html', 'Content-Length': '192', 'Server': 'gunicorn/19.9.0', 'Via': '1.1 google', 'Alt-Svc': 'quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000'} / '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n<title>400 Bad Request</title>\n<h1>Bad Request</h1>\n<p>The browser (or proxy) sent a request that this server could not understand.</p>\n'

生成的请求 URL 和打开的 id 令牌似乎是正确的 在代码的最后部分引发了错误

resp = requests.request(
    method, url,
    headers={'Authorization': 'Bearer {}'.format(
        google_open_id_connect_token)}, **kwargs)
if resp.status_code == 403:
    raise Exception('Service account {} does not have permission to '
                    'access the IAP-protected application.'.format(
                        signer_email))
elif resp.status_code != 200:
    raise Exception(
        'Bad response from application: {!r} / {!r} / {!r}'.format(
            resp.status_code, resp.headers, resp.text))

谢谢

【问题讨论】:

    标签: python google-cloud-platform google-cloud-functions google-cloud-storage google-cloud-composer


    【解决方案1】:

    最初的问题中反映的错误码400 Bad Request更多的时候是对应客户端的问题,确实应该首先检查DAG触发的输入参数,调用IAP的函数在代码@987654323中调用@:

    def make_iap_request(url, client_id, method='GET', **kwargs)
    

    确保您已通过requirements.txt 文件应用了针对受 IAP 保护的 URL 运行所需的依赖项。

    不要忘记验证您传递给此函数的基本参数:

    url:要获取的受身份识别代理保护的 URL。

    client_id:Identity-Aware Proxy 使用的客户端 ID。

    到目前为止,我还没有找到更好的触发 DAG 的亲身体验,然后由 @Jacob Ferriero 在他伟大的 article 中解释。

    【讨论】:

    • 谢谢,我解决了我的问题,make_iap_request 函数的requests.request( method, url, headers={'Authorization': 'Bearer {}'.format( google_open_id_connect_token)}, **kwargs) 有问题。我不需要任何参数来调用气流,所以我没有使用任何 kwarg。调用函数似乎需要 JSON 参数
    猜你喜欢
    • 1970-01-01
    • 2023-03-14
    • 2021-02-27
    • 2019-02-15
    • 2018-12-07
    • 2018-10-02
    • 2021-01-22
    • 1970-01-01
    • 2020-12-09
    相关资源
    最近更新 更多