首页 > 解决方案 > 使用 mailchimp_transactional 客户端有什么问题?

问题描述

我收到此错误:

  File "/Users/hernan0216/services/project/services/email.py", line 84, in _send_template
    result = self.client.messages.send_template(**data)
  File "/Users/hernan0216/services/venv/lib/python3.6/site-packages/mailchimp_transactional/api/messages_api.py", line 422, in send_template
    (data) = self.send_template_with_http_info(body, **kwargs)  # noqa: E501
  File "/Users/hernan0216/services/venv/lib/python3.6/site-packages/mailchimp_transactional/api/messages_api.py", line 438, in send_template_with_http_info
    " to method send_template" % key
TypeError: Got an unexpected keyword argument 'template_name' to method send_template

数据应该是这样的

data = {'template_name': 'name_template', 'template_content': [], 'message': {'from_email': 'noreply@ex.com', 'from_name': 'Ex', 'subject': "some string", 'to': [{'email': 'ex@example.com', 'name': 'Example', 'type': 'to'}], 'global_merge_vars': [{'name': 'STUDENT_NAME', 'content': 'Example Name'}]}}

Like 在 mailchimp api文档中为 send_template 方法指定

在 mailchimp_transactional 客户端中,我找到了这段代码,说比只接受“body”作为关键字参数,我应该打开一个问题吗?应该在客户端、文档或 api 上?也许我错过了一些东西,如果是这样的话,对不起。

标签: pythonmailchimpmandrillmailchimp-api-v3.0

解决方案


只需将其作为常规body参数而不是关键字参数传递 - 没有**. 关键字 params 语法必须在旧版 Mandrill Python API 中使用,Mailchimp Transactional API 不需要它。

result = self.client.messages.send_template(data)

推荐阅读