【问题标题】:How do I automate this sendinblue api?如何自动化这个 sendinblue api?
【发布时间】:2019-09-13 19:51:47
【问题描述】:

尝试自动将联系人添加到 sendinblue 的 api。他们网站上给出的示例显示了添加电子邮件,然后将其添加到您帐户中的列表中。

我已经尝试过 fstrings 和 .format(email, industry, role) 但由于某种原因它不断抛出错误。

这是他们的网站显示的内容。

import requests

url = "https://api.sendinblue.com/v3/contacts"

payload = "{\"email\":\"someonesEmail97@gmail.com\",\"listIds\":[1,4],\"updateEnabled\":false}"
headers = {
    'accept': "application/json",
    'content-type': "application/json"
    }

response = requests.request("POST", url, data=payload, headers=headers

这是我尝试过的

import requests

url = "https://api.sendinblue.com/v3/contacts"

payload = "{\"email\":\f"{email}"\",\"listIds\":[f"{industry}",f"{role}"],\"updateEnabled\":false}"
headers = {
    'accept': "application/json",
    'content-type': "application/json"
    }

response = requests.request("POST", url, data=payload, headers=headers)

我希望在我网站的注册部分中使用它,这样它就会抓取他们经过身份验证的电子邮件并将其添加到我设置的适当列表中。但是我从使用 fstrings 得到的结果是终端中指向电子邮件字段的语法无效。 然后我尝试了 .format 并没有在终端上显示任何错误,但在网页上我得到了这个错误


payload = "{\"email\":\{}\",\"listIds\":[{},{}],\"updateEnabled\":false}".format(email, industry, role)

/accounts/signup/activate/ 处的 KeyError “'电子邮件'” 指向有效载荷所在的行。

我错过了什么?感谢阅读

【问题讨论】:

    标签: python django sendinblue


    【解决方案1】:

    我从使用 fstrings 得到的结果是终端中的无效语法 指向电子邮件字段

    那是因为你有引号不匹配,并且你试图以一种奇怪的、无效的方式创建 f 字符串。

    试试这个:

    payload = f'{{"email":"{email}","listIds":[{industry},{role}],"updateEnabled":false}}'
    

    【讨论】:

    • 那主要是因为我很奇怪,无效。感谢那!真的很感谢它的反应。
    • 这听起来不像是一种侮辱。你是有效的!
    • 不,我是在开玩笑 :D 非常感谢您的帮助。没有你的有效!
    猜你喜欢
    • 1970-01-01
    • 2012-04-15
    • 1970-01-01
    • 2021-02-15
    • 2014-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多