首页 > 解决方案 > 使用 eventlet.monkey_patch() 请求“未找到地址”异常

问题描述

这段代码:

主文件

import eventlet
eventlet.monkey_patch() # commenting this line makes the app run correctly
import requests

response = requests.get('http://localhost:8080/position') # exception thrown here

抛出以下异常:

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

但是,如果我评论eventlet.monkey_patch(),它可以工作。

我必须做猴子补丁,因为我目前正在使用Flask-SocketIOeventlet希望拥有后台线程(根据他们的文档)。有谁知道如何解决这一问题?

版本:

小事件: 0.30.2请求:2.25.1

标签: python-requestsflask-socketiomonkeypatchingeventlet

解决方案


推荐阅读