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

使用cbpro调用get_fills返回'message'字符串无实际内容的问题

Troubleshooting AttributeError When Using cbpro's get_fills Method

I ran into a similar quirk with the cbpro library not long ago, so I know exactly where you're stuck. Let's break down what's happening and how to fix it.

What's Causing the Error?

The root issue is that for certain products, the Coinbase API returns an error response—but the cbpro library isn’t parsing that response into a proper dictionary (like the official docs say it should). Instead, it passes through the raw JSON string (which looks like the plain string "message" when you print it directly), leading to that AttributeError when you try to call .items() on it.

Common triggers for this API error include:

  • You’ve never traded that product before (the API throws an error instead of returning an empty list)
  • The product has been delisted from Coinbase
  • Your API key lacks permissions to access data for that product
  • Temporary API rate limiting or service issues

How to See the Actual Error Message

To fix this and view the real error content, add a check for string responses and manually parse them into JSON. Here's your modified code:

import json

all_fills = {}
for product in products:
    all_fills[product] = []
    fills = a.get_fills(product)
    for fill in fills:
        # Handle error responses that come as raw strings
        if isinstance(fill, str):
            try:
                # Convert the string to a proper JSON object
                error_dict = json.loads(fill)
                print(f"Error fetching fills for {product}: {error_dict.get('message', 'Unknown error')}")
            except json.JSONDecodeError:
                # Fallback if the string isn't valid JSON
                print(f"Unexpected response for {product}: {fill}")
            # Skip to the next entry since this one is an error
            continue
        
        # Process valid fill objects as originally intended
        for x, y in fill.items():
            print(f"\t{x}: {y}")
        print(fill)
        all_fills[product].append(fill)
    print(f"{product} captured.")

Additional Checks to Try

  • Validate product IDs: Double-check that the pairs in your products list are still active on Coinbase—some older pairs get delisted over time.
  • Confirm API permissions: Ensure your API key has the view permission enabled (required to fetch fill history).
  • Update cbpro: Older versions of the library have buggy error handling. Run pip install --upgrade cbpro to grab the latest release.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 07:55:13