python-websockets / websockets

Library for building WebSocket servers and clients in Python
https://websockets.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
5.21k stars 515 forks source link

A bug in python 3.7? #432

Closed yjqiang closed 6 years ago

yjqiang commented 6 years ago

cannot 'yield from' a coroutine object in a non-coroutine generaorator.

RuntimeWarning: coroutine "BaseEventLoop.create_ connection" was never awaited.

yjqiang commented 6 years ago

try: self.ws = await websockets.connect('wss://broadcastlv.chat.bilibili.com/sub', timeout=3) except: print("# 连接无法建立,请检查本地网络状况") print(sys.exc_info()[0], sys.exc_info()[1]) return False

yjqiang commented 6 years ago

It works well in python 3.6, while crash in python 3.7.

RemiCardona commented 6 years ago

Could you print the python backtrace here ? Thanks

yjqiang commented 6 years ago

<class 'TypeError'> cannot 'yield from' a coroutine object in a non-coroutine generaorator.

(The code I showed before)RuntimeWarning: coroutine "BaseEventLoop.create_ connection" was never awaited.

yjqiang commented 6 years ago

That is all it shows to me. But you can run the code I gave, and print more information.

yjqiang commented 6 years ago

https://github.com/yjqiang/bilibili-live-tools/blob/master/bilibiliCilent.py

https://github.com/yjqiang/bilibili-live-tools/blob/master/connect.py

These are the concrete codes

RemiCardona commented 6 years ago

You're hiding the backtrace, please remove the try/except and let the full backtrace print on screen, and copy paste that. Thanks

yjqiang commented 6 years ago

Traceback (most recent call last): File "0.py(1).py", line 15, in loop.run_until_complete(run()) File "D:\Python\lib\asyncio\base_events.py", line 568, in run_until_complete return future.result() File "0.py(1).py", line 7, in run ws = await websockets.connect('wss://broadcastlv.chat.bilibili.com/sub', timeout=3) File "D:\Python\lib\site-packages\websockets\client.py", line 397, in await transport, protocol = yield from self._creating_connection TypeError: cannot 'yield from' a coroutine object in a non-coroutine generator sys:1: RuntimeWarning: coroutine 'BaseEventLoop.create_connection' was never awaited

RemiCardona commented 6 years ago

Dupe of #405 then. 3.7 is supported on master - which I encourage you to test - and the next release will include the necessary changes. Closing. Thanks

yjqiang commented 6 years ago

I noticed that once, but couldn't find in a short time, so I thought it is the feature for python3.8. LOL. Anyway thanks a lot.

aaugustin commented 6 years ago

Version 6.0 adds support for Python 3.7 and is now available on PyPI: https://pypi.org/project/websockets/6.0/#files