我想向 Sendpulse API 发送以下发布请求,但收到错误:
“标签应该是一个数组”。
我认为我的标签字段是一个数组。请问是什么原因以及如何解决?
def add_tag(self, contact_id, tag_name):
url = base_url_whatsapp + "/contacts/setTag"
payload_data = {
"contact_id": str(contact_id),
"tags": [
tag_name
]
}
headers = {
'Authorization': f'Bearer {self.access_token}',
'Content-Type': 'application/json'
}
response = requests.post(url, headers=headers, params=payload_data)
if response.status_code == 200:
print('Add Tag Successful')
#print(response.json()) # If you expect a JSON response
else:
print('Request failed:', response.text)
我期待着成功的回应
您可能应该使用
data
的 requests.post()
参数而不是 params
,因此有效负载作为正文传递:
response = requests.post(url, headers=headers, data=payload_data)