Flask restful服务无法与VPN一起工作

2024-05-21 16:30:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Flask restful服务,我可以通过以下方式访问它:

    st = "http://0.0.0.0:3000/sentence={}"
    url_str = st.format(text).replace('\n', '')
    req = requests.get(url_str).content
    bs = json.loads(BeautifulSoup(req, features="html.parser").string)

我可以在自己的电脑上访问它

但是,如果我在我的计算机上启动VPN服务,然后想启动此restful,它总是失败:

Traceback (most recent call last):
  File "/my-envs/dialog-envs/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/my-envs/dialog-envs/lib/python3.7/site-packages/urllib3/connectionpool.py", line 384, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/my-envs/dialog-envs/lib/python3.7/site-packages/urllib3/connectionpool.py", line 380, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1321, in getresponse
    response.begin()
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 296, in begin
    version, status, reason = self._read_status()
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 257, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 589, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer

During handling of the above exception, another exception occurred:

为什么我必须关闭“VPN”才能运行restful


Tags: inpyrestfulhttplibusrlocalline