HTTPConnectionPool(host='xxxx', port=y):读取超时。

在我的 python 脚本中,有多个 API 调用,并且 API 在同一个应用程序中!我正在使用 django 框架!通过 python3 manage.py runserver 它工作正常!


但是在带有 nginx 服务器、主管、gunicorn 的 centos7 虚拟机中,调用第三个 API 后它无法正常工作!


出现了这个错误:


The complete exception is provided below:

<class 'requests.exceptions.ReadTimeout'>

HTTPConnectionPool(host='x.x.x.x', port=y): Read timed out. (read timeout=None)

在 nginx 错误日志中只有这个错误:


[error] 12020#12020: *133 upstream prematurely closed connection while reading response header from upstream, client:

需要一些帮助


蓝山帝景
浏览 542回答 1
1回答

子衿沉夜

终于我找到了解决办法!其实是因为gunicom和nginx的超时。我的脚本需要 30 多秒,所以请更新我的 gunicorn 配置文件!这是配置:[program:project]command = gunicorn -c /opt/project/gunicorn_config.py project.wsgi -t 300directory = project directoryuser = usernginx配置也需要添加这个代理设置:location / {&nbsp; &nbsp; proxy_pass http://127.0.0.1:8001;&nbsp; &nbsp; proxy_set_header X-Forwarded-Host $server_name;&nbsp; &nbsp; proxy_set_header X-Real-IP $remote_addr;&nbsp; &nbsp; proxy_set_header X-Forwarded-Proto $scheme;&nbsp; &nbsp; add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';&nbsp; &nbsp; proxy_read_timeout 300s;&nbsp; &nbsp; proxy_connect_timeout 300s;}谢谢!如果有人遇到同样的问题,希望这会有所帮助!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python