通过Google云功能触发DAG

时间:2019-12-30 18:30:22

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

当文件到达基于云{{3}的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))

谢谢

1 个答案:

答案 0 :(得分:0)

最初问题中反映的错误代码400 Bad Request经常与客户端问题相对应,实际上,首先应检查DAG触发的输入参数,调用IAP的函数代码example

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

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

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

  

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

     

client_id:身份识别代理使用的客户端ID。

到目前为止,我还没有发现更好的触发DAG的经验,@Jacob Ferriero在其出色的article中对此进行了解释。