RasaHQ / rasa

šŸ’¬ Open source machine learning framework to automate text- and voice-based conversations: NLU, dialogue management, connect to Slack, Facebook, and more - Create chatbots and voice assistants
https://rasa.com/docs/rasa/
Apache License 2.0
18.63k stars 4.6k forks source link

'Server' object has no attribute 'attach' in rasa 1.0.2 #3659

Closed kellymestre closed 5 years ago

kellymestre commented 5 years ago

Hello,

I've a custom connector,

from socketio import Server
from rasa.core.channels.socketio import SocketBlueprint, SocketIOInput

class CustomSocketIOChannelInput(SocketIOInput):
    def blueprint(self, on_new_message):
        sio = Server()
        socketio_webhook = SocketBlueprint(
            sio, self.socketio_path, 'socketio_webhook', __name__)
...

and after upgrading to rasa 1.0.2, I'm getting the following error:

Traceback (most recent call last):
  File "web.py", line 37, in <module>
    S = AGENT.handle_channels([INPUT_CHANNEL], 5002)
  File "/Users/kellymestre/Documents/Work/Repo/dihkbot/ihkenv/lib/python3.7/site-packages/rasa/core/agent.py", line 682, in handle_channels
    app = run.configure_app(channels, cors, None, enable_api=False, route=route)
  File "/Users/kellymestre/Documents/Work/Repo/dihkbot/ihkenv/lib/python3.7/site-packages/rasa/core/run.py", line 85, in configure_app
    rasa.core.channels.channel.register(input_channels, app, route=route)
  File "/Users/kellymestre/Documents/Work/Repo/dihkbot/ihkenv/lib/python3.7/site-packages/rasa/core/channels/channel.py", line 75, in register
    app.blueprint(channel.blueprint(handler), url_prefix=p)
  File "/Users/kellymestre/Documents/Work/Repo/dihkbot/ihkenv/lib/python3.7/site-packages/sanic/app.py", line 699, in blueprint
    blueprint.register(self, options)
  File "/Users/kellymestre/Documents/Work/Repo/dihkbot/ihkenv/lib/python3.7/site-packages/rasa/core/channels/socketio.py", line 21, in register
    self.sio.attach(app, self.socketio_path)
AttributeError: 'Server' object has no attribute 'attach'

I've checked the socketio.py under rasa.core.channels.socketio and now on the SocketBlueprint register there is in fact the line self.sio.attach(app, self.socketio_path). And the AsyncServer has the attach function but the Server does not have.

Is there any solution for that?

Thanks in advance!

akelad commented 5 years ago

Thanks for raising this issue, @tabergma will get back to you about it soon.

tabergma commented 5 years ago

Hi @kellymestre, I guess you need to use AsyncServer instead of Server. Can you try the following code snippet?

from socketio import AsyncServer
from rasa.core.channels.socketio import SocketBlueprint, SocketIOInput

class CustomSocketIOChannelInput(SocketIOInput):
    def blueprint(self, on_new_message):
        sio = AsyncServer()
        socketio_webhook = SocketBlueprint(
            sio, self.socketio_path, 'socketio_webhook', __name__)
...
kellymestre commented 5 years ago

Hi @tabergma , thanks for helping me with this issue! Yes in the mean time I changed to that approach and it works. But I still get an error, which I do not know if it is related or not with this:

[2019-06-04 09:42:10 +0100] [1631] [ERROR] Exception occurred in one of response middleware handlers
Traceback (most recent call last):
  File ā€œā€¦/lib/python3.7/site-packages/sanic/app.py", line 958, in handle_request
    request, response
  File ā€œā€¦/lib/python3.7/site-packages/spf/framework.py", line 543, in _run_response_middleware
    _response = await _response
  File ā€œā€¦/lib/python3.7/site-packages/sanic_cors/extension.py", line 266, in unapplied_cors_response_middleware
    set_cors_headers(req, resp, context, res_options)
  File ā€œā€¦/lib/python3.7/site-packages/sanic_cors/core.py", line 248, in set_cors_headers
    if resp.headers is None:
AttributeError: 'list' object has no attribute 'headers'

This error does not prevent me to interact with the it but I'm always getting it.

Thanks!

tabergma commented 5 years ago

Glad it works now. Regarding the error: It seems like there is something wrong with the response. Can you please share the code that is leading to that error? What are you trying to do?

kellymestre commented 5 years ago

Hi @tabergma , sorry just an update regarding my previous comment, so I was using sio = AsyncServer(async_mode="sanic") and this way it works, but I get that error ('list' object has no attribute 'headers') when refreshing the page where I have the rasa-webchat connection. I limited the messages to have the structure {"text": "text"} but even this way I'm getting the error.

If is use sio = AsyncServer() as you suggested I get the following exception:

Traceback (most recent call last):
  File "web.py", line 37, in <module>
    S = AGENT.handle_channels([INPUT_CHANNEL], 5003)
  File ".../lib/python3.7/site-packages/rasa/core/agent.py", line 680, in handle_channels
    app = run.configure_app(channels, cors, None, enable_api=False, route=route)
  File ".../lib/python3.7/site-packages/rasa/core/run.py", line 85, in configure_app
    rasa.core.channels.channel.register(input_channels, app, route=route)
  File ".../lib/python3.7/site-packages/rasa/core/channels/channel.py", line 75, in register
    app.blueprint(channel.blueprint(handler), url_prefix=p)
  File ".../lib/python3.7/site-packages/sanic/app.py", line 699, in blueprint
    blueprint.register(self, options)
  File ".../lib/python3.7/site-packages/rasa/core/channels/socketio.py", line 21, in register
    self.sio.attach(app, self.socketio_path)
  File ".../lib/python3.7/site-packages/socketio/asyncio_server.py", line 76, in attach
    self.eio.attach(app, socketio_path)
  File ".../lib/python3.7/site-packages/engineio/asyncio_server.py", line 64, in attach
    self._async['create_route'](app, self, '/{}/'.format(engineio_path))
  File ".../lib/python3.7/site-packages/engineio/async_drivers/aiohttp.py", line 16, in create_route
    app.router.add_get(engineio_endpoint, engineio_server.handle_request)
AttributeError: 'Router' object has no attribute 'add_get'
tabergma commented 5 years ago

@kellymestre Thanks for pointing out that you should use AsyncServer(async_mode="sanic"). Regarding the AttributeError: 'list' object has no attribute 'headers': Is that still a problem? If yes, can you please share the request you are doing? Otherwise I would close the issue.

kellymestre commented 5 years ago

@tabergma yes I still get that exception. The information that I was able to retrieve regarding the request where this exception is being triggered is the following:

Request: <Request: GET /socket.io/>

Request Headers: <CIMultiDict('host': 'localhost:5002', 'connection': 'Upgrade', 'pragma': 'no-cache', 'cache-control': 'no-cache', 'upgrade': 'websocket', 'origin': 'http://localhost', 'sec-websocket-version': '13', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8', 'cookie': 'io=f8adc324292c4653882ff0ff1f57aa33', 'sec-websocket-key': 'Tol0PGDGYezSCPsHpaQz4w==', 'sec-websocket-extensions': 'permessage-deflate; client_max_window_bits')>

Request URL: ws://localhost:5002/socket.io/?EIO=3&transport=websocket&sid=f8adc324292c4653882ff0ff1f57aa33

Response.header => throws exception AttributeError: 'list' object has no attribute 'headers'

tmbo commented 5 years ago

This error does not seem to be Rasa related anymore.