[英]sendgrid error "403 access forbidden" when trying to create sub user
[英]Unable to test Sendgrid locally with HTTP Error 403: Forbidden
我正在尝试使用 Sendgrid 进行基本测试,但我的请求不断收到 403 和 401。
我正在使用 localhost 开发服务器进行测试,以模拟对我的端点的请求。 我的 sendgrid 密钥存储在 .env 中,就像我的密钥的 rest 作为 sendgrid_api_key 一样。 我的 API 密钥可以完全访问 sendgrid。 我已经安装了 sendgrid==6.9.7
import os
import sendgrid
def sendgrid_welcome_email(request):
try:
sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('sendgrid_api_key'))
response = sg.client.contactdb.lists.get()
print(response.status_code)
print(response.body)
print(response.headers)
except Exception as ex:
print("Unexpected error: " + str(ex))
return "Bad", 500
错误“意外错误:HTTP 错误 403:禁止”
所以我通过使用另一个客户端端点解决了它,我认为我查看的文档很旧。
import os
from sendgrid import SendGridAPIClient
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
data = {
"contacts": [
{
"email": "ryan39@lee-young.com"
}
]
}
response = sg.client.marketing.contacts.put(
request_body=data
)
print(response.status_code)
print(response.body)
print(response.headers)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.