Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referencing to #324: Explicit set of transports=['websocket'] causes "'NoneType' object has no attribute 'ws_connect'" #152

Closed
Nexodaru opened this issue Dec 10, 2019 · 3 comments
Assignees
Labels

Comments

@Nexodaru
Copy link

Nexodaru commented Dec 10, 2019

I work with socket.io but this issue is related to the new engineio commit referenced in title.
commit

Reproduce Example:

client = socketio.AsyncClient(logger=True, engineio_logger=True)
await client.connect('http://localhost:{}'.format(server.port), transports=['websocket'])

Raises:

aiohttp_server = <function aiohttp_server.<locals>.go at 0x7f7b55bb3ee0>, geocatch = <Application 0x7f7b5647c250>

    @pytest.mark.asyncio
    async def test_connect(aiohttp_server, geocatch):
        server = await aiohttp_server(geocatch)
        client = socketio.AsyncClient(logger=True, engineio_logger=True)
        refused = False
        try:
>           await client.connect('http://localhost:{}'.format(server.port), transports=['websocket'])

tests/integration/test_connect.py:42: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv/lib/python3.8/site-packages/socketio/asyncio_client.py:106: in connect
    await self.eio.connect(url, headers=headers,
venv/lib/python3.8/site-packages/engineio/asyncio_client.py:75: in connect
    return await getattr(self, '_connect_' + self.transports[0])(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <engineio.asyncio_client.AsyncClient object at 0x7f7b55b83ca0>, url = 'http://localhost:41433', headers = {}, engineio_path = 'socket.io'

    async def _connect_websocket(self, url, headers, engineio_path):
        """Establish or upgrade to a WebSocket connection with the server."""
        if aiohttp is None:  # pragma: no cover
            self.logger.error('aiohttp package not installed')
            return False
        websocket_url = self._get_engineio_url(url, engineio_path,
                                               'websocket')
        if self.sid:
            self.logger.info(
                'Attempting WebSocket upgrade to ' + websocket_url)
            upgrade = True
            websocket_url += '&sid=' + self.sid
        else:
            upgrade = False
            self.base_url = websocket_url
            self.logger.info(
                'Attempting WebSocket connection to ' + websocket_url)
    
        try:
            if not self.ssl_verify:
                ssl_context = ssl.create_default_context()
                ssl_context.check_hostname = False
                ssl_context.verify_mode = ssl.CERT_NONE
                ws = await self.http.ws_connect(
                    websocket_url + self._get_url_timestamp(),
                    headers=headers, ssl=ssl_context)
            else:
>               ws = await self.http.ws_connect(
                    websocket_url + self._get_url_timestamp(),
                    headers=headers)
E                   AttributeError: 'NoneType' object has no attribute 'ws_connect'

venv/lib/python3.8/site-packages/engineio/asyncio_client.py:251: AttributeError

Without setting transports to websockets it seems to work.

Not sure but http is only set in the method _send_request() in client.py, which is only called in _connect_polling(). When I explicit set transports to websocket, socketio/asycnio_client calls connect of engineio/asyncio_client, which executes this:

    async def connect(self, url, headers={}, transports=None,
                      engineio_path='engine.io'):
         ...

        return await getattr(self, '_connect_' + self.transports[0])(
            url, headers, engineio_path)

This references to the method _connect_websocket(self, url, headers, engineio_path) which trys to use self.http, which was never initialized.

Without setting transports to websockets, polling is upgraded to websockets. So http already was initialized and it works.

@miguelgrinberg miguelgrinberg self-assigned this Dec 10, 2019
@miguelgrinberg
Copy link
Owner

Yeah, this is a side-effect of the switch to the aiohttp websocket client. Sorry about that I'll take care of this.

@simplextech
Copy link

This change is also causing me issues with the aioambient module that uses this. Same error as the title.

@miguelgrinberg
Copy link
Owner

Could you give the master branch a try and confirm this issue is addressed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants