# sqlalchemy.exc.OperationalError：(psycopg2.OperationalError) 无法将主机名 "db.example.com" 转换为地址：名称解析临时失败

- **ID:** `python/sqlalchemy-connection-ssl-error`
- **领域:** python
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

数据库主机名的 DNS 解析失败。

## 版本兼容性

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

## 解决方案

1. **Check DNS configuration and network connectivity.** (90% 成功率)
   ```
   nslookup db.example.com
ping db.example.com
   ```
2. **Use IP address temporarily and fix DNS.** (85% 成功率)
   ```
   engine = create_engine('postgresql://user:pass@192.168.1.100/dbname')
   ```

## 无效尝试

- **Hardcoding IP address in connection string.** — IP may change; not portable. (60% 失败率)
- **Increasing connection timeout.** — DNS failure persists regardless of timeout. (80% 失败率)
