python network_error ai_generated true

requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8080): 超过最大重试次数 (由NewConnectionError('<urllib3.connection.HTTPConnection object at 0x...>: 无法建立新连接:[Errno 111] 连接被拒绝')引起)

requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x...>: Failed to establish a new connection: [Errno 111] Connection refused'))

ID: python/requests-connectionerror-connection-refused

其他格式: JSON · Markdown 中文 · English
80%修复率
88%置信度
0证据数
2025-07-30首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

指定主机和端口上没有服务在监听。

English

No service is listening on the specified host and port.

generic

解决方案

  1. 95% 成功率 Start the server or ensure it is running on the correct port
    Check if the server is running: netstat -tulpn | grep 8080
    # Start the server if needed
  2. 80% 成功率 Use a different port that the server is actually listening on
    requests.get('http://localhost:3000')  # if server runs on port 3000

无效尝试

常见但无效的做法:

  1. Increasing the timeout value 95% 失败

    The connection is refused immediately, so timeout does not matter.

  2. Using a different protocol (e.g., HTTPS instead of HTTP) 90% 失败

    The port is not open for any protocol.