jinnatar / python-cozify

Unofficial Cozify Python bindings and helpers
MIT License
16 stars 4 forks source link

cozify.Error.APIError: API error, 410: API version outdated. Update python-cozify. Gone - https://cloud2.cozify.fi/ui/0.2/hub/remote/cc/1.10/hub/tz - #14

Closed Kirbo closed 5 years ago

Kirbo commented 6 years ago
cozify.Error.APIError: API error, 410: API version outdated. Update python-cozify. Gone - https://cloud2.cozify.fi/ui/0.2/hub/remote/cc/1.10/hub/tz - 

What should i do? I tried git pull but it didn't help.

Kirbo commented 6 years ago

...tried also increasing the API version from 1.10 to 1.11 here https://github.com/Artanicus/python-cozify/blob/8eaadc89cd9c8ed8bc9dc1f9fc1ddcff1c609342/cozify/hub_api.py#L14, but that didn't work either

jinnatar commented 6 years ago

I forgot to push the commit to GitHub, sorry! 1fc7658df2c8bb0b5f075da682813eb6f820f88f has the API bump. It did work locally but since you're accessing remotely that may be the issue. My guess, the remote API has gotten refactored upstream and needs to be re-written but will have time later today to investigate further.

Kirbo commented 6 years ago

Any updates on this? Is there some information/something i could provide or help you with or something i could try out or anything?

jinnatar commented 6 years ago

I'm having a hard time replicating the issue. Here's what I just did on a remote machine and everything seems to work ok:

%> pip3 install cozify
# *snip lots of output*
 %> python3 -i
Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cozify import cloud, hub
>>> cloud.authenticate()
Enter your Cozify account email address: xxx@xxx.com
OTP from your email: V3NU9X
True
>>> cloud.authenticate()
True
>>> hub.tz()
'Europe/Helsinki'
>>> hub.remote(hub.default())
True
>>> hub.devices(id=hub.default())
{'f0be9529-f282-4810-916b-c8775c1151e0': {'zones': [], 'rwx': 509, 'groups': [], 'manufacturer': 'Philips', 'type': 'LIGHT', 'capabilities': {'type': 'SET', 'values': ['COLOR_TEMP', 'TRANSITION', 'COLOR_HS', 'BRIGHTNESS', 'IDENTIFY', 'CONTROL_LIGHT', 'ON_OFF', 'DEVICE', 'COLOR_LOOP', 'UPGRADE', 'ALERT']}, 'name': 'Hue', 'timestamp': 1542726064263, 'id': 'f0be9529-f282-4810-916b-c8775c1151e0', 'state': {'lastSeen': 1542485635256, 'hue': -1, 'type': 'STATE_LIGHT', 'transitionMsec': None, 'maxTemperature': 6535.9477124183, 'colorMode': 'ct',
# *snip much much more devices*
>>> import cozify
>>> cozify.__version__
'0.2.18'

Can you check if this simple test repeats your issue?

Kirbo commented 6 years ago
$ pip3 install cozify
Collecting cozify
  Downloading https://files.pythonhosted.org/packages/2f/ea/fb7dc5440e6189b32517ecd66776a741726f647ec314368376f7b03d0909/cozify-0.2.18-py3-none-any.whl
Collecting requests (from cozify)
  Downloading https://files.pythonhosted.org/packages/ff/17/5cbb026005115301a8fb2f9b0e3e8d32313142fe8b617070e7baad20554f/requests-2.20.1-py2.py3-none-any.whl (57kB)
    100% |████████████████████████████████| 61kB 4.0MB/s 
Collecting absl-py (from cozify)
  Downloading https://files.pythonhosted.org/packages/0c/63/f505d2d4c21db849cf80bad517f0065a30be6b006b0a5637f1b95584a305/absl-py-0.6.1.tar.gz (94kB)
    100% |████████████████████████████████| 102kB 4.0MB/s 
Collecting certifi>=2017.4.17 (from requests->cozify)
  Downloading https://files.pythonhosted.org/packages/56/9d/1d02dd80bc4cd955f98980f28c5ee2200e1209292d5f9e9cc8d030d18655/certifi-2018.10.15-py2.py3-none-any.whl (146kB)
    100% |████████████████████████████████| 153kB 3.4MB/s 
Collecting idna<2.8,>=2.5 (from requests->cozify)
  Downloading https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 8.4MB/s 
Collecting chardet<3.1.0,>=3.0.2 (from requests->cozify)
  Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 3.6MB/s 
Collecting urllib3<1.25,>=1.21.1 (from requests->cozify)
  Downloading https://files.pythonhosted.org/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whl (118kB)
    100% |████████████████████████████████| 122kB 4.4MB/s 
Collecting six (from absl-py->cozify)
  Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Building wheels for collected packages: absl-py
  Running setup.py bdist_wheel for absl-py ... done
  Stored in directory: /home/user/.cache/pip/wheels/18/ea/5e/e36e1b8739e78cd2eba0a08fdc602c2b16a4b263912af8cb64
Successfully built absl-py
Installing collected packages: certifi, idna, chardet, urllib3, requests, six, absl-py, cozify
Successfully installed absl-py-0.6.1 certifi-2018.10.15 chardet-3.0.4 cozify-0.2.18 idna-2.7 requests-2.20.1 six-1.11.0 urllib3-1.24.1
$ python3 -i
Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cozify import cloud, hub
>>> cloud.authenticate()
OTP from your email: <email here>
WARNING: Logging before flag parsing goes to stderr.
E1120 17:19:41.766805 140580296369920 cloud.py:56] OTP authentication has failed.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/lib/python3.5/site-packages/cozify/cloud.py", line 54, in authenticate
    cloud_token = cloud_api.emaillogin(email, otp)
  File "/home/user/.local/lib/python3.5/site-packages/cozify/cloud_api.py", line 45, in emaillogin
    raise APIError(response.status_code, response.text)
cozify.Error.APIError: API error, 401: Authentication failed.
>>> 
Kirbo commented 6 years ago

Actually now that i deleted the old ~/.config/python-cozify/python-cozify.cfg file and tried again, it worked.

Kirbo commented 6 years ago

Yup, now it seems to be working again. Should've tried deleting the old .cfg in the first place. The cozify-sample-loop.py that i'm running keeps messing up the config file every now and then (could it be if my home internet is down and the script cannot fetch the status of sensors? I haven't debugged that far yet), so i created the following script that i'm running in screen:

#!/bin/bash

echo "Navigating into the path"
cd /home/user/cozify-temp

echo "Pulling latest changes"
git pull

echo "Copying: python-cozify.cfg_working"
cp ~/.config/python-cozify/python-cozify.cfg_working ~/.config/python-cozify/python-cozify.cfg

echo "Copying .config/python-cozify/python-cozify.cfg_working into .config/python-cozify/python-cozify.cfg"
cp ~/.config/python-cozify/python-cozify.cfg_working ~/.config/python-cozify/python-cozify.cfg

echo "Running: /home/user/cozify-temp/cozify-sample-loop.py"
until /home/user/cozify-temp/cozify-sample-loop.py; do
    echo "Navigating into the path"
    cd /home/user/cozify-temp

    echo "Pulling latest changes"
    git pull

    echo "Copying: python-cozify.cfg_working"
    cp ~/.config/python-cozify/python-cozify.cfg_working ~/.config/python-cozify/python-cozify.cfg

    echo "Copying .config/python-cozify/python-cozify.cfg_working into .config/python-cozify/python-cozify.cfg"
    cp ~/.config/python-cozify/python-cozify.cfg_working ~/.config/python-cozify/python-cozify.cfg

    echo "'cozify-sample-loop.py' crashed with exit code $?. Restarting..." >&2
    sleep 1
done

...and that has been working for several weeks/months, now all the sudden it stopped working and threw the error i started this issue in the first place and it didn't come into my mind to try and delete the ~/.config/python-cozify/python-cozify.cfg and let it be automatically generated again.

You may close this issue since it is obsolete. 🙂