Python Forum

Full Version: Error TypeError: '<=' not supported between instances of 'int' and 'NoneType'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I am new to python and working on the creating client of websocket API. In One function I am getting the error
[b]if 3000 <= code < 4000:
Output:
TypeError: '<=' not supported between instances of 'int' and 'NoneType'[/b]
the complete error is

*********************
Error:
Traceback (most recent call last): File "c:\Users\Development\Documents\Python\WebSocket\WebsocketSample_Phython.py", line 577, in <module> asyncio.get_event_loop().run_until_complete(functionCall()) File "C:\Users\Development\AppData\Local\Programs\Python\Python36-32\lib\asyncio\base_events.py", line 468, in run_until_complete return future.result() File "c:\Users\Development\Documents\Python\WebSocket\WebsocketSample_Phython.py", line 569, in functionCall await GetInstruments() File "c:\Users\Development\Documents\Python\WebSocket\WebsocketSample_Phython.py", line 453, in GetInstruments response = await websocket.recv() File "C:\Users\Development\AppData\Local\Programs\Python\Python36-32\lib\site-packages\websockets\protocol.py", line 323, in recv raise ConnectionClosed(self.close_code, self.close_reason) File "C:\Users\Development\AppData\Local\Programs\Python\Python36-32\lib\site-packages\websockets\exceptions.py", line 147, in __init__ if 3000 <= code < 4000: TypeError: '<=' not supported between instances of 'int' and 'NoneType'
*********************

How can I fix this?

Thanks and regards
Dhananjay Kale
Hi, next time please use proper tags for formating the post, you can find help here.

The error message suggests that the code variable holds a None value, which obviously cannot be compared to a number. So check the rest of your program to find how code becomes None. It could be you intended to assign code a result of a function with no return statement. By default functions return None. If you are unsure, post the rest of your code in Python code tags.