gpt4 book ai didi

python-2.7 - HTTP 错误 : HTTP Error 401: Unauthorized for sendgrid integration with python

转载 作者:行者123 更新时间:2023-12-03 16:42:13 25 4
gpt4 key购买 nike

def sendEmail(to,apNumber,paperType,zipedFile):

sg = sendgrid.SendGridAPIClient(apikey=os.environ.get("API-KEY"))

to_email = mail.Email( "to@email.com")
from_email = mail.Email( "from@email.com" )
subject = 'This is a test email'
content = mail.Content('text/plain', 'Example message.')
message = mail.Mail(from_email, subject, to_email, content)
response = sg.client.mail.send.post(request_body = message.get())
return response

最佳答案

设置环境变量。

要设置环境变量,请按照以下 3 个步骤操作

echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env

关于python-2.7 - HTTP 错误 : HTTP Error 401: Unauthorized for sendgrid integration with python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39717986/

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