tasmota / decode-config

Backup/restore and decode configuration tool for Tasmota
GNU Lesser General Public License v3.0
211 stars 32 forks source link

Syntax Error for use of 'nonlocal' #65

Closed jkwim closed 1 year ago

jkwim commented 1 year ago

Describe the bug

ubuntu@ubuntu:~/tasmota/configs/decode-config-development$ ./decode-config.py -s 192.168.1.221
  File "./decode-config.py", line 4071
    nonlocal ack_flag
                    ^
SyntaxError: invalid syntax

To Reproduce

Steps to reproduce the behavior: 1. Program parameter: 2. Result:

Expected behavior

A clear and concise description of what you expected to happen.

Version Information

Please complete the following information
use decode-config.py -V to retrieve the info


ubuntu@ubuntu:~/tasmota/configs/decode-config-development$ ./decode-config.py -V
  File "./decode-config.py", line 4071
    nonlocal ack_flag
                    ^
SyntaxError: invalid syntax
ubuntu@ubuntu:~/tasmota/configs/decode-config-development$ ./decode-config.py -v
  File "./decode-config.py", line 4071
    nonlocal ack_flag
                    ^
SyntaxError: invalid syntax

System' information of your Tasmota data

Append -g System to your decode-config parameter, e. g. decode-config.py -s myconfig.dmp -g System


>>> paste output here <<<

Additional context

ubuntu@ubuntu:~/tasmota/configs/decode-config-development$ pip3 install -r requirements.txt
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: requests in /home/ubuntu/.local/lib/python3.8/site-packages (from -r requirements.txt (line 1)) (2.25.1)
Requirement already satisfied: configargparse in /home/ubuntu/.local/lib/python3.8/site-packages (from -r requirements.txt (line 2)) (1.5.3)
Collecting paho-mqtt
  Downloading paho-mqtt-1.6.1.tar.gz (99 kB)
     |████████████████████████████████| 99 kB 157 kB/s
Requirement already satisfied: idna<3,>=2.5 in /usr/lib/python3/dist-packages (from requests->-r requirements.txt (line 1)) (2.8)
Requirement already satisfied: certifi>=2017.4.17 in /home/ubuntu/.local/lib/python3.8/site-packages (from requests->-r requirements.txt (line 1)) (2021.5.30)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/lib/python3/dist-packages (from requests->-r requirements.txt (line 1)) (1.25.8)
Requirement already satisfied: chardet<5,>=3.0.2 in /usr/lib/python3/dist-packages (from requests->-r requirements.txt (line 1)) (3.0.4)
Building wheels for collected packages: paho-mqtt
  Building wheel for paho-mqtt (setup.py) ... done
  Created wheel for paho-mqtt: filename=paho_mqtt-1.6.1-py3-none-any.whl size=62132 sha256=edd30e7c52ee7a5d638b646f416384488224e6a56913d18b66cdb228b75b0406
  Stored in directory: /home/ubuntu/.cache/pip/wheels/6a/48/01/c895c027e9b9367ec5470fbf371ee56e795a49ac6a19aa4c9f
Successfully built paho-mqtt
Installing collected packages: paho-mqtt
Successfully installed paho-mqtt-1.6.1
WARNING: You are using pip version 21.1.3; however, version 22.3.1 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command.

Note: I wanted to use the latest development branch because I cannot use the latest release version due to limitation of reading Tasmota 12.3.1.3.

This is the version that I have using pip3 install -r requirements.txt

ubuntu@ubuntu:~/tasmota/configs/$ decode-config.py -V
decode-config.py v12.3.1.0 [728642d] by Norbert Richter nr@prsolution.eu

Script:   decode-config.py
Version:  12.3.1.0 [728642d]
Python:   3.8.10
Platform: Linux-5.4.0-1078-raspi-aarch64-with-glibc2.29 - aarch64
OS:       Linux 5.4.0-1078-raspi #89-Ubuntu SMP PREEMPT Mon Dec 5 08:38:35 UTC 2022
Time:     2023-01-16 19:39:00

This version works with Tasmota 12.1.1.2 but not with 12.3.1.3

WARNING 6: Tasmota configuration data v12.3.1.3 currently unsupported! The read
           configuration data is newer than the last supported v12.3.1 by this
           program. Newer Tasmota versions may contain changed data structures
           so that the data with older versions may become incompatible. You
           can force proceeding at your own risk by appending the parameter '--
           ignore-warnings'. Be warned: Forcing can lead to unpredictable
           results for your Tasmota device. In the worst case, your Tasmota
           device  will not respond and you will have to flash it again using
           the serial interface. If you are unsure and do not know the  changes
           in the configuration structure, you may able to use the developer
           version of this program from https://github.com/tasmota/decode-
           config/tree/development.
Premature exit - #6 Unsupported version
curzon01 commented 1 year ago

Your first call started python2 from somewhere, nonlocal is a python3 keyword, this error occurs if you try to run the script using python2

Your python installation seems to be a mix of python2 and python3 - check and cleanup

curzon01 commented 1 year ago

Can not be reproduce

It looks like a local mixup of outdated script and/or mix of python env.

jkwim commented 1 year ago

Ah! Yes, I have both.

ubuntu@ubuntu:~/tasmota/configs$ python -V
Python 2.7.18
ubuntu@ubuntu:~/tasmota/configs$ python3 -V
Python 3.8.10

Changed here and it works now:

ubuntu@ubuntu:~/tasmota/configs/decode-config-development$ more decode-config.py    
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function
ubuntu@ubuntu:~/tasmota/configs/decode-config-development$ ./decode-config.py -s $deviceip  -g System | jq
{
  "bootcount": 9,
  "bootcount_reset_time": 1673771115,
  "cfg_crc": "0x764d",
  "cfg_crc32": "0xc1a45fcc",
  "cfg_holder": 4617,
  "cfg_size": 4096,
  "cfg_timestamp": 1673891708,
  "header": {
    "data": {
      "crc": "0xb91e",
      "crc32": "0xc1a45fcc",
      "hardware": "ESP82",
      "size": 4096,
      "version": {
        "id": "0xc030103",
        "name": "12.3.1.3"
      }
    },
    "env": {
      "platform": "Linux-5.4.0-1078-raspi-aarch64-with-glibc2.29",
      "python": "3.8.10",
      "script": "decode-config.py v12.3.1.3 [7e18bc3]",
      "system": "Linux aarch64 5.4.0-1078-raspi #89-Ubuntu SMP PREEMPT Mon Dec 5 08:38:35 UTC 2022"
    },
    "template": {
      "crc": "0x764d",
      "crc32": "0xc1a45fcc",
      "size": 4096,
      "version": {
        "id": "0xc030103",
        "name": "12.3.1.3"
      }
    },
    "timestamp": "2023-01-16 17:55:08"
  },
  "version": "0xc030103"
}
pgorod commented 1 year ago

I had this same problem, fixed it with the change to "python3" inside the file.

I don't know much about Python environments, but I gather this is not a bug but a configuration problem? Should I worry? How should I fix my setup? I only use it for decode-config, on this computer.

Thanks

curzon01 commented 1 year ago

That's nothing to worry about.

The error occurs when decode-config is started with an outdated Python V2 (has reached EOL 01 Jan 2020), but decode-config is written for Python V3.

The script expects the command python starts a V3. This should also be the operating system default because V2 should be an exception due to EOL.

If you have both versions installed, you should configure your system so that the command python starts a python V3, not V2 and V2 only starts when python2 is explicitly entered or simnply uninstall V2. How this works, depends on your OS, there is no general answer.