scrool / xled

🎄Unofficial control for Twinkly - Smart Decoration LED lights.
MIT License
204 stars 46 forks source link

AttributeError: module 'xled' has no attribute 'security' #95

Closed bodagetta closed 2 years ago

bodagetta commented 2 years ago

Summary

I'm running the sample code and get the following error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/michael.whitley/Developer/xled/xled/control.py", line 226, in get_device_info
    response = self.session.get(url)
  File "/Users/michael.whitley/opt/anaconda3/lib/python3.8/site-packages/requests/sessions.py", line 543, in get
    return self.request('GET', url, **kwargs)
  File "/Users/michael.whitley/Developer/xled/xled/auth.py", line 329, in request
    headers = self.add_authorization(headers)
  File "/Users/michael.whitley/Developer/xled/xled/auth.py", line 354, in add_authorization
    self.fetch_token()
  File "/Users/michael.whitley/Developer/xled/xled/auth.py", line 272, in fetch_token
    self.client.challenge_response_valid(self.hw_address)
  File "/Users/michael.whitley/Developer/xled/xled/auth.py", line 396, in challenge_response_valid
    expected = xled.security.make_challenge_response(self._challenge, hw_address)
AttributeError: module 'xled' has no attribute 'security'```

# Affected XLED components

- [ ] Command Line Interface (CLI)
- [x] Libary
- [ ] Documentation
- [ ] Other

# XLED version
v0.6.1-62-g624b519

# Twinkly device details
<!--- Project support only some device models. Provide details by calling its API where HOSTNAME is either IP address or host name of your device. -->

## Device information

```{"product_name":"Twinkly","hardware_version":"304","bytes_per_led":3,"hw_id":"c55a6c","flash_size":64,"led_type":14,"product_code":"TWS400STP","fw_family":"F","device_name":"Twinkly_C55A6D","uptime":"236293617","mac":"a4:e5:7c:xx:xx:xx","uuid":"FFB78939-XXXX-XXXX-XXXX-A11CB1AXXXXX","max_supported_led":510,"number_of_led":400,"led_profile":"RGB","frame_rate":13,"measured_frame_rate":15.38,"movie_capacity":3382,"wire_type":2,"copyright":"LEDWORKS 2021","code":1000}

Firmware version

Operating system

MacOS

Python version

Python 3.8.5

Steps to reproduce

import xled discovered_device = xled.discover.discover() discovered_device.id control = xled.ControlInterface(discovered_device.ip_address, discovered_device.hw_address) control.get_device_info()['number_of_led']

Expected behavior

Return number of LEDs

Actual results


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/michael.whitley/Developer/xled/xled/control.py", line 226, in get_device_info
    response = self.session.get(url)
  File "/Users/michael.whitley/opt/anaconda3/lib/python3.8/site-packages/requests/sessions.py", line 543, in get
    return self.request('GET', url, **kwargs)
  File "/Users/michael.whitley/Developer/xled/xled/auth.py", line 329, in request
    headers = self.add_authorization(headers)
  File "/Users/michael.whitley/Developer/xled/xled/auth.py", line 354, in add_authorization
    self.fetch_token()
  File "/Users/michael.whitley/Developer/xled/xled/auth.py", line 272, in fetch_token
    self.client.challenge_response_valid(self.hw_address)
  File "/Users/michael.whitley/Developer/xled/xled/auth.py", line 396, in challenge_response_valid
    expected = xled.security.make_challenge_response(self._challenge, hw_address)
AttributeError: module 'xled' has no attribute 'security'```
# Additional information

<!--- Anything else you would like to add? -->
I love the work done on this and look forward to using it!
scrool commented 2 years ago

Please edit your report and format the code with https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#quoting-code

bodagetta commented 2 years ago

Done - sorry about that!

Anders-Holst commented 2 years ago

I can not manage to repeat it here - with python 3.6 it works fine. However, I notice something fishy in auth.py - two incompatible ways of import. Maybe python 3.8 is more picky with such things.

@bodagetta , please try to remove line 31 in auth.py, which reads from xled.security import generate_challenge, and then try again to see if the problem persists.

bodagetta commented 2 years ago

@Anders-Holst I tried commenting out line 31 from auth.py as requested and it is then missing that import.


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/michael.whitley/Developer/xled/xled/control.py", line 226, in get_device_info
    response = self.session.get(url)
  File "/Users/michael.whitley/Developer/xled/xled/control.py", line 77, in session
    self._session = BaseUrlChallengeResponseAuthSession(
  File "/Users/michael.whitley/Developer/xled/xled/auth.py", line 219, in __init__
    self.client = client or ClientApplication()
  File "/Users/michael.whitley/Developer/xled/xled/auth.py", line 415, in __init__
    self.challenge = challenge or generate_challenge
NameError: name 'generate_challenge' is not defined```
Anders-Holst commented 2 years ago

Ah, I see. Then on line 415 where it says self.challenge = challenge or generate_challenge, can you add xled.security. before generate_challenge, so it says: self.challenge = challenge or xled.security.generate_challenge. And try again.

bodagetta commented 2 years ago

sorry for delay - Thanksgiving happened.

I tried that change and it works - it returns 400.

Thanks!

scrool commented 2 years ago

I'm closing this as from previous comment it looks like not a bug.