gpt4 book ai didi

python - SparkPost:至少需要一个有效的收件人 python/django API

转载 作者:行者123 更新时间:2023-11-30 22:59:23 26 4
gpt4 key购买 nike

我在使用 SparkPost 发送电子邮件时遇到问题:我的代码如下:

from configurations.global_configs import site_base_url
from media.settings import SPARKPOST_API_KEY
from sparkpost import SparkPost
import traceback

def welcome_email(user_profile):
try:
user_profile.confirmation_key = user_profile.generate_key()
user_profile.save()
email_address = user_profile.user.email
print email_address
name = user_profile.user.first_name or email_address
email_confirmation_url = site_base_url + "api/account/signup/?ck=" + user_profile.confirmation_key
print email_confirmation_url
sp = SparkPost(SPARKPOST_API_KEY)
result = sp.transmissions.send(
recipients=[email_address],
template='welcome',
subject='this is my subject',
track_opens=True,
track_clicks=True,
substitution_data={
'email_validation_url': email_confirmation_url
},
transactional= True
)
return result
except:
traceback.print_exc()

但是我的代码输出如下并返回此错误:

exampleemail@gmail.com
http://example.com/api/account/signup/?ck=1144f138439dc42e
Traceback (most recent call last):
File "./users_system/services/email_confirm.py", line 28, in welcome_email
transactional= True
File "/usr/local/lib/python2.7/dist-packages/sparkpost/transmissions.py", line 142, in send
results = self.request('POST', self.uri, data=json.dumps(payload))
File "/usr/local/lib/python2.7/dist-packages/sparkpost/base.py", line 26, in request
raise SparkPostAPIException(response)
SparkPostAPIException: Call to https://api.sparkpost.com/api/v1/transmissions returned 400, errors:

At least one valid recipient is required:

如您所见,我有一个收件人,并且我知道这是有效的,因为我通过 Sparkpost 仪表板发送了测试邮件。但为什么我收到此错误“至少需要一个有效的收件人”???!!!我的问题出在哪里

最佳答案

我找到了答案,首先我要感谢 Sparkpost 支持团队,问题出在 Spark 模块中的电子邮件解析器中,并且创建该问题是为了在我的代码中解决它,我进行了此更改来修复它:
收件人=[ dict(address=dict(email=email_address)) ],

关于python - SparkPost:至少需要一个有效的收件人 python/django API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35771408/

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