我正在尝试使用Mailchimp API的批处理功能。我现在的设置是这样的
operations = []
for idx, row in users_df.iterows():
payload = {
'email': row['email'],
'last_updated': row['new_time'],
'custom_value': row['new_value']
}
operation_item = {
"method": "POST", # I changed this to PUT
"path": '/lists/members/12345',
"body": json.dumps(payload),
}
operations.append(operation_item)
client = mc.MailChimp(MAILCHIMP_TOKEN, MAILCHIMP_USER)
batch = client.batches.create(data={"operations": operations})
每当我使用POST方法时,都会出现以下错误:old_user@gmail.com is already a list member. Use PUT to insert or update list members.
但每当我将方法更改为PUT时,就会出现另一个错误:The requested method and resource are not compatible. See the Allow header for this resource's available methods.
您不能将资源放入列表
"/lists/members/12345"
,您需要将路径更改为"/lists/members/12345/{email}"
此代码适用于我们:
使用受保护的方法
client.lists.members._build_path
是有点黑客我猜,如果你喜欢你可以手动构建的网址,它将f'lists/{list_id}/members/{user.email}'
相关问题 更多 >
编程相关推荐