# 类型错误：期望一个协程，但得到 <class 'str'>

- **ID:** `python/asyncio-sync-primitive-type-error`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

将非协程对象（例如字符串）传递给期望协程的 asyncio 函数，如 asyncio.wait() 或 asyncio.gather()。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |

## 解决方案

1. **Ensure the function is defined as async and called correctly** (95% 成功率)
   ```
   async def my_coro():
    return 'result'
await asyncio.gather(my_coro())
   ```
2. **Use asyncio.iscoroutine() to check before passing** (90% 成功率)
   ```
   if asyncio.iscoroutine(obj):
    await asyncio.gather(obj)
else:
    # handle non-coroutine
   ```

## 无效尝试

- **Wrapping the object in a list** — The function still expects coroutines, not a list of strings. (70% 失败率)
- **Using asyncio.ensure_future() on the object** — ensure_future() expects a coroutine or future, not a string. (60% 失败率)
