I am getting Attribute error: 'module' object has no attribute 'enableTrace' while running a python code
Asked Answered
A

3

8

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'

Autobiographical answered 20/3, 2017 at 14:7 Comment(0)
E
17

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.

Ecumenicity answered 14/9, 2018 at 14:4 Comment(1)
Solved it for me ! thanks !Edmead
D
6

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
Driver answered 9/7, 2022 at 0:40 Comment(0)
S
6

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.

Starch answered 11/7, 2022 at 7:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.