运行Rasa Stack时,超过最大重试次数并且连接被拒绝错误

时间:2019-05-21 08:49:03

标签: python python-requests urllib3 rasa-nlu rasa-core

Rasa版本:Core = 0.14.4,Core-sdk = 0.14.0,NLU = 0.15.0

Python版本:3.6.7

操作系统(windows,osx等):Ubuntu 18.04.2 LTS

问题:我一直在使用Rasa Stack入门包(https://github.com/RasaHQ/starter-pack-rasa-stack),对于它中的文件,除了Makefile(我将python的实例更改为python3)之外,其中的文件保持不变。我试图按照https://rasa.com/docs/core/connectors/#rest-channels中的说明使用RestInput通道使Rasa Stack作为服务器工作。我使用了该示例,使用运行脚本连接其余输入通道:

python3 -m rasa_core.run -d models/current/dialogue -u models/current/nlu --port 5002 --credential credentials.yml

这最初是可行的,但是我尝试使用以下代码发布消息:

import requests

URL = 'http://localhost:5010/webhooks/rest/webhook/'
PARAMS = {'sender': "ola", 'message': "how are you"}

r = requests.get(URL)

data = r.json()
print(data)

导致与url和连接拒绝超过最大重试次数有关的错误。从那以后的问题是,无论有没有命令行界面,我都无法启动和运行服务器。当我尝试如上所述连接其余输入通道时,出现以下错误:

r/lib/python3.6/runpy.py:125: RuntimeWarning: 'rasa_core.run' found in sys.modules after import of package 'rasa_core', but prior to execution of 'rasa_core.run'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))
2019-05-21 08:38:27 INFO     root  - Rasa process starting
2019-05-21 08:38:45 INFO     rasa_nlu.components  - Added 'SpacyNLP' to component cache. Key 'SpacyNLP-en'.
Traceback (most recent call last):
  File "/home/thales/.local/lib/python3.6/site-packages/urllib3/connection.py", line 160, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/home/thales/.local/lib/python3.6/site-packages/urllib3/util/connection.py", line 80, in create_connection
    raise err
  File "/home/thales/.local/lib/python3.6/site-packages/urllib3/util/connection.py", line 70, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/thales/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 603, in urlopen
    chunked=chunked)
  File "/home/thales/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 355, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/home/thales/.local/lib/python3.6/site-packages/urllib3/connection.py", line 183, in connect
    conn = self._new_conn()
  File "/home/thales/.local/lib/python3.6/site-packages/urllib3/connection.py", line 169, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f58af883ba8>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/thales/.local/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/home/thales/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 641, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/home/thales/.local/lib/python3.6/site-packages/urllib3/util/retry.py", line 399, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=5002): Max retries exceeded with url: /webhooks/rest/webhook/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f58af883ba8>: Failed to establish a new connection: [Errno 111] Connection refused',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.6/dist-packages/rasa_core/run.py", line 204, in <module>
    endpoints=_endpoints)
  File "/usr/local/lib/python3.6/dist-packages/rasa_core/run.py", line 157, in load_agent
    from rasa_core import agent
  File "/usr/local/lib/python3.6/dist-packages/rasa_core/agent.py", line 14, in <module>
    from rasa_core.channels import UserMessage, OutputChannel, InputChannel
  File "/usr/local/lib/python3.6/dist-packages/rasa_core/channels/__init__.py", line 23, in <module>
    from rasa_core.channels.telegram import TelegramInput  # nopep8
  File "/usr/local/lib/python3.6/dist-packages/rasa_core/channels/telegram.py", line 4, in <module>
    from telegram import (
  File "/home/thales/.local/lib/python3.6/site-packages/telegram/__init__.py", line 46, in <module>
    from .files.file import File
  File "/home/thales/.local/lib/python3.6/site-packages/telegram/files/file.py", line 23, in <module>
    from future.backports.urllib import parse as urllib_parse
  File "/home/thales/.local/lib/python3.6/site-packages/future/backports/__init__.py", line 14, in <module>
    import_top_level_modules()
  File "/home/thales/.local/lib/python3.6/site-packages/future/standard_library/__init__.py", line 810, in import_top_level_modules
    with exclude_local_folder_imports(*TOP_LEVEL_MODULES):
  File "/home/thales/.local/lib/python3.6/site-packages/future/standard_library/__init__.py", line 781, in __enter__
    module = __import__(m, level=0)
  File "/home/thales/ola/starter-pack-rasa-stack/test.py", line 6, in <module>
    r = requests.post(URL, data = PARAMS)
  File "/home/thales/.local/lib/python3.6/site-packages/requests/api.py", line 116, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/home/thales/.local/lib/python3.6/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/thales/.local/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/thales/.local/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/home/thales/.local/lib/python3.6/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=5002): Max retries exceeded with url: /webhooks/rest/webhook/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f58af883ba8>: Failed to establish a new connection: [Errno 111] Connection refused',))

提及端口的错误部分似乎取决于我的帖子python脚本中的端口。命令行参数中的端口似乎被忽略了。我尝试调试run.py文件时发现它在“来自rasa_core导入代理”的第157行崩溃了,这没有什么意义,因为该导入在python终端中本身就可以正常工作。

“ make cmdline”命令会产生与“ make train-core”命令相同的错误。

我应该注意,我仍然可以为其他内容创建动作服务器和本地服务器。

配置文件(config.yml)的内容:

language: "en"
pipeline: spacy_sklearn

1 个答案:

答案 0 :(得分:0)

似乎您提供的电报凭证错误。如果您错过了任何内容,请查阅文档here

如果您使用包含localhost的URL指定了Webhook URL:如果Telegram尝试将用户消息转发给机器人,则此URL是可访问的,因为该URL是内部的。您可以例如使用ngrok使该网址公开可用。