Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Smtp 从GCP composer发送电子邮件时出错_Smtp_Airflow_Sendgrid_Http Status Code 401_Google Cloud Composer - Fatal编程技术网

Smtp 从GCP composer发送电子邮件时出错

Smtp 从GCP composer发送电子邮件时出错,smtp,airflow,sendgrid,http-status-code-401,google-cloud-composer,Smtp,Airflow,Sendgrid,Http Status Code 401,Google Cloud Composer,我正在尝试配置电子邮件,但出现以下错误。 运行任务时出现以下错误:- 我正在GCP Composer中使用Python3和airflow 10.3版本,需要帮助 My气流.cfg [email] email_backend = airflow.contrib.utils.sendgrid.send_email [smtp] smtp_host = smtp.gmail.com smtp_starttls = True smtp_ssl = False smtp_user

我正在尝试配置电子邮件,但出现以下错误。 运行任务时出现以下错误:- 我正在GCP Composer中使用Python3和airflow 10.3版本,需要帮助

My气流.cfg

[email]  
email_backend = airflow.contrib.utils.sendgrid.send_email  

[smtp]  
smtp_host = smtp.gmail.com  
smtp_starttls = True  
smtp_ssl = False  
smtp_user = airflow  
smtp_port = 587  
smtp_password = mypassword  
smtp_mail_from = myemail@gamil.com  
在我的dag文件中,我创建了任务:- dag.py文件:-

来自afflow.operators.email\u operator导入EmailOperator
email\u task=EmailOperator(task\u id='email\u task',to='email@gamil.com,subject=“test”,html\u content=“此处最重要的标题”,files=None,cc=None,bcc=None,mime\u subtype='mixed',mime\u charset='us\u ascii',dag=dag)
获取错误:

错误-HTTP错误401:未经授权 python_http_client.exceptions.UnauthorizedError:http错误401:Unauthorize


该错误是授权错误,因此您需要检查是否正确设置了Sendgrid API密钥(或密码,如果使用smtp服务器)

根据你的airflow.cfg,在我看来,你正在尝试使用Sendgrid和第三方smtp服务器

电子邮件标志决定使用哪一个。在这种情况下,标志
email\u backend=afflow.contrib.utils.sendgrid.send\u email
指定要使用sendgrid

要作为电子邮件服务器,您需要获取
SENDGRID\u API\u密钥
,并将密钥和
SENDGRID\u MAIL\u FROM
设置为环境变量


另一方面,如果需要,则必须将电子邮件标志更改为
email\u backend=afflow.utils.email.send\u email\u smtp
。在这种情况下,您需要覆盖smtp用户和密码。

使用Google Cloud Composer,您必须设置: SENDGRID\u MAIL\u FROM 及 SENDGRID\u API\u密钥 编写器“环境变量”