1

尝试自动将联系人添加到 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/ "'email'" 处的 KeyError 指向有效负载打开的行。

我错过了什么?谢谢阅读

4

1 回答 1

2

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

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

尝试这个:

payload = f'{{"email":"{email}","listIds":[{industry},{role}],"updateEnabled":false}}'
于 2019-09-13T19:59:09.593 回答