# 无法从字符串 'postgresql://user:pass@localhost/db' 解析 rfc1738 URL

- **ID:** `python/sqlalchemy-exc-argument-error-unknown-dialect`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

提供给 create_engine() 的数据库 URL 格式错误或缺少必需组件（如驱动或主机）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **Correct URL format with driver** (95% 成功率)
   ```
   Use the correct format: 'postgresql+psycopg2://user:pass@localhost:5432/dbname'
   ```
2. **Use connect_args dictionary** (85% 成功率)
   ```
   Use a dictionary for connection parameters instead of URL, e.g., create_engine('postgresql+psycopg2://', connect_args={'host': 'localhost'})
   ```

## 无效尝试

- **Adding extra slashes** —  (60% 失败率)
- **Using wrong driver name** —  (70% 失败率)
