I Am Getting Attribute Error: 'Module' Object Has No Attribute 'Enabletrace' While Running a Python Code

I am using python 2.7 and I have installed the module websocket-client 0.40.0 but I am getting the attribute error as I mentioned above.

This is my code, I am trying to connect my PC to a microcontroller board through websocket

import websocket
import nltk
from nltk.tokenize import PunktSentenceTokenizer
import sys
import urllib
import urlparse
from urllib2 import HTTPError
from urllib2 import URLError
from getch import getch, pause
import numpy as np
websocket.enableTrace(True)
ws = websocket.create_connection("ws://169.254.7.144:1234") 

When I run this program I am getting the error

File "on_laptop.py", line 35, in

websocket.enableTrace(True)

AttributeError: 'module' object has no attribute 'enableTrace'

3 Answers

You've probably installed the websocket package (which doesn't have an enableTrace method) instead of websocket-client.

pip install websocket-client should solve your problem.

1

Don't forget to uninstall websocket, uninstall websocket-client if you already intalled it before, then re install websocket-client:

  1. pip uninstall websocket
  2. pip uninstall websocket-client
  3. pip install websocket-client

For anyone who finds this issue later on (since it is currently the top hit on Google for this particular issue).

In addition to the already existing solutions, also make sure you do not have a file named "websocket.py". If you do, this will override the websocket-client module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest