td-ameritrade-python-api icon indicating copy to clipboard operation
td-ameritrade-python-api copied to clipboard

Any pointers to help? Streaming issue (error: websockets.exceptions.NegotiationError: Unsupported extension: name = permessage-deflate, params = [])

Open gmstuff opened this issue 4 years ago • 4 comments

Hi all

I know it has to be me, but I cant find out what I did wrong! Can anybody point me in the right direction please ?

Thanks in advance!!

Short version : When running the code as per Alex's streaming video on youtube i get an error "websockets.exceptions.NegotiationError: Unsupported extension: name = permessage-deflate, params = []"

I got to that error via a 'fix' ?? of an earlier error: Both are documented below

My environment on the new Virtual Machine:

  • VS Code 1.60.1
  • Python 3.8.2 32bit (on Windows 10) (on my initial machine I was using Python 3.9.0 64bit)

After hours of googling and trying different mods I then tried to a 'clean' environment - Built out a virtual machine Windows 10, fresh install of Visual Studio Code, fresh install of Python 3.8.2 (Same as the version in the video) - still getting errors (Error #2 in second block below)

Any pointers at all would be great!! Thanks again!

Initial error before the mod suggested in discussion 183 (https://github.com/areed1192/td-ameritrade-python-api/discussions/183) Which basically said put the line below under the line "import websockets" in the file : td/stream.py from websockets import client

After doing the above I got past that error, but was faced with the second error (Which is where I am stuck at)

First Error: (appearing to be resolved by github discussion doc 183) This is all the errors PRIOR to adding this to the td/stream.py file "from websockets import client": PS C:\VS_Code\TD_API> & C:/Users/gerar/AppData/Local/Programs/Python/Python38-32/python.exe c:/VS_Code/TD_API/Using_Stream_Client.py Traceback (most recent call last): File "c:/VS_Code/TD_API/Using_Stream_Client.py", line 23, in td_stream_client.stream(True) File "C:\Users\gerar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\td\stream.py", line 539, in stream self.loop.run_until_complete(self._connect()) File "C:\Users\gerar\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 616, in run_until_complete
return future.result() File "C:\Users\gerar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\td\stream.py", line 636, in _connect self.connection = await websockets.client.connect(self.websocket_url) File "C:\Users\gerar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\websockets\imports.py", line 92, in getattr raise AttributeError(f"module {package!r} has no attribute {name!r}") AttributeError: module 'websockets' has no attribute 'client' PS C:\VS_Code\TD_API>

********** second error - the one I am now stuck on ********************** So am now using the same example code, but with the td/stream.py modified by adding the line "from websockets import client"

I get the below errors:


PS C:\VS_Code\TD_API> & C:/Users/gerar/AppData/Local/Programs/Python/Python38-32/python.exe c:/VS_Code/TD_API/Using_Stream_Client.py Traceback (most recent call last): File "c:/VS_Code/TD_API/Using_Stream_Client.py", line 23, in td_stream_client.stream(True) File "C:\Users\gerar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\td\stream.py", line 539, in stream self.loop.run_until_complete(self._connect()) File "C:\Users\gerar\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 616, in run_until_complete return future.result() File "C:\Users\gerar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\td\stream.py", line 636, in _connect self.connection = await websockets.client.connect(self.websocket_url) File "C:\Users\gerar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\websockets\legacy\client.py", line 649, in await_impl_timeout return await asyncio.wait_for(self.await_impl(), self.open_timeout) File "C:\Users\gerar\AppData\Local\Programs\Python\Python38-32\lib\asyncio\tasks.py", line 483, in wait_for return fut.result() File "C:\Users\gerar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\websockets\legacy\client.py", line 660, in await_impl await protocol.handshake( File "C:\Users\gerar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\websockets\legacy\client.py", line 331, in handshake self.extensions = self.process_extensions( File "C:\Users\gerar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\websockets\legacy\client.py", line 220, in process_extensions raise NegotiationError( websockets.exceptions.NegotiationError: Unsupported extension: name = permessage-deflate, params = [] PS C:\VS_Code\TD_API>


PS C:\VS_Code\TD_API> pip list
Package Version


certifi 2021.5.30 cffi 1.14.6
charset-normalizer 2.0.6 click 8.0.1 colorama 0.4.4 cryptography 3.4.8 Flask 2.0.1 idna 3.2
itsdangerous 2.0.1 Jinja2 3.0.1 MarkupSafe 2.0.1 oauthlib 3.1.1 pip 21.2.4 pycparser 2.20 pyOpenSSL 20.0.1 requests 2.26.0 requests-oauthlib 1.3.0 setuptools 41.2.0 six 1.16.0 td-ameritrade-python-api 0.3.5 urllib3 1.26.6 websockets 10.0 Werkzeug 2.0.1 PS C:\VS_Code\TD_API>

python code is attached as a text file Sample_py.txt

gmstuff avatar Sep 18 '21 20:09 gmstuff

Update : I was kinda thinking this was a WebSockets compatibility issue, so I reviewed Alex's streaming video again, took a note of what version of WebSockets he was running and saw he had V 8.0.2.

I uninstalled my WebSockets V10, installed WebSockets 8.0.2 and the script ran without errors, pulling back minimal data (but then it is Saturday out of hours)

So the question I guess becomes, erm.... is this an issue with the TD api or the WebSockets library?

gmstuff avatar Sep 18 '21 21:09 gmstuff

I get the same issue, but cannot get an install of websockets 8.0.2 to work. Any other ideas?

lilbumblebear avatar Dec 31 '21 22:12 lilbumblebear

I was having the same issue when I moved over to a new host. My previous host was running websockets 8.1. I was able to downgrade websockets from 10.1 to 8.1 and it got rid of the AttributeError: module 'websockets' has no attribute 'client'. I had tried the 9.1 that is in requirement.txt of this branch, but it got the same error. So I am up and running on websockets 8.1.

sbaldwin72 avatar Jan 02 '22 07:01 sbaldwin72

I changed the following in stream.py

        # Create a connection.
#        self.connection = await websockets.client.connect(self.websocket_url)
        self.connection = await websockets.connect(self.websocket_url)

This is working with Websockets 10

chotaGit avatar Jan 18 '22 13:01 chotaGit