You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mailchimp API v3 Python调用报错:list()仅接受1个参数却传入2个

Fixing Mailchimp API v3 Campaign List Filter TypeError

I’ve dealt with this exact pitfall using the Mailchimp Python SDK—let’s walk through what’s causing the error and how to fix it.

The Root Cause

The client.campaigns.list() method doesn’t accept a single positional argument (like a dictionary or list). Instead, it expects keyword arguments that map directly to the API’s query parameters. Your error occurs because you’re passing a dictionary/list as a positional parameter, but the method is designed to take individual keyword params.

Correct Code Example

Here’s the proper way to filter campaigns by list_id:

import mailchimp_marketing as MailchimpMarketing
from mailchimp_marketing.api_client import ApiClientError

try:
    client = MailchimpMarketing.Client()
    client.set_config({ 
        "api_key": "YOUR_API_KEY", 
        "server": "YOUR_SERVER_PREFIX"  # e.g., "us1" from your API key
    })
    
    # Pass list_id as a direct keyword argument
    response = client.campaigns.list(list_id="YOUR_TARGET_LIST_ID")
    print(response)
except ApiClientError as error:
    print("Error: {}".format(error.text))

Why Your Previous Attempts Failed

Let’s break down why each of your code snippets threw the same error:

  • client.campaigns.list({"campaigns": [{"recipients": {"list_id": "xyz"}}]}): The campaigns parameter doesn’t exist for the list endpoint—this nested structure isn’t recognized by the API.
  • client.campaigns.list([{"recipients": {"list_id": "xyz"}}]): Passing a list as a positional argument is invalid; the method doesn’t accept list inputs here.
  • client.campaigns.list({"recipients": {"list_id": "xyz"}}): The API doesn’t expect a nested recipients object for filtering. The list_id is a top-level query parameter, not part of a nested structure.
  • client.campaigns.list({"list_id": "xyz"}): You’re passing a dictionary as a single positional argument, but the method expects keyword arguments (e.g., list_id="xyz"), not a single dict.

Advanced Filtering (If Needed)

If you need to combine multiple filters (e.g., list_id + campaign status), use multiple keyword arguments directly:

# Example: Filter by list_id AND "sent" status
response = client.campaigns.list(
    list_id="YOUR_LIST_ID",
    status="sent"
)

内容的提问来源于stack exchange,提问作者Xlsx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 08:37:34