我使用python和pycharm通过Mailchimp API将成员添加到列表中。但每当我发送一组成员时,当我去检查列表时,只有大约85%的成员号码被添加。例如,如果我发送300个成员,则只有大约256个成员进入列表。如果我发送大约500名会员,只有大约425名会员进入名单。为什么会这样?我该如何解决这个问题?(提前谢谢)
这是我的代码:
# coding: utf-8
from mailchimp3 import MailChimp
import json
from pprint import pprint
MAILCHIMP_USER="My_user_name"
MAILCHIMP_KEY="my_mailchimp_key"
# Declaracao funcao que envia listas para o mailchimp
def export_to_mailchimp():
with open('my_list_of_members_path.json', 'r') as f:
data = f.read()
data = "[" + data.replace("}", "},", data.count("}") - 1) + "]"
json_data = json.loads(data)
pprint(json_data)
print(json_data[0])
#SETANADO O CLIENT
client = MailChimp(mc_user=MAILCHIMP_USER, mc_api=MAILCHIMP_KEY)
# Create list for dictionaries
operations = []
i=0
#loop through queryset
for user_list in json_data:
# Create dictionary for body
databody_item = {
"user_id": user_list['User_id'],
"email_address": user_list['Email'],
"status": "subscribed",
"merge_fields": {
"FNAME": user_list['First_name'],
"LNAME": user_list['Last_name']
},
"country": user_list['Country'],
"city": user_list['City'],
"unsubscribe": user_list['Unsubscribe'],
"qty_reservas": user_list['Reservas']
}
# Create dictionary for a operation 17923aaab6
operation_item = {"method": "POST", "path": "path_to_my_mailchimp_list", "body": json.dumps(databody_item)}
# Append to list
operations.append(operation_item)
print(databody_item)
print(i)
i=i+1
batch = client.batches.create(data={"operations": operations})
# ENVIA A TABELA PARA O MAILCHIMP
export_to_mailchimp()
就像我说的,代码工作正常,唯一的问题是缺少成员。