Ankermgmt / ankermake-m5-protocol

Ankermake M5 protocol specifications and libraries *NOT AFFILIATED WITH ANKER*
GNU General Public License v3.0
164 stars 36 forks source link

ankerctl config import broken #25

Closed spuder closed 1 year ago

spuder commented 1 year ago

Seeing this error when running an ankerctl config import (on the chrivers/pppp-improvements branch commit: 0339ef71782e6e8e4bdafd507659cfa7ad365b68)

./ankerctl.py config import
[*] Loading cache..
[*] Initializing API..
[*] Requesting profile data..
Traceback (most recent call last):
  File "/Users/spuder/Code/github/Ankermgmt/ankermake-m5-protocol/./ankerctl.py", line 369, in <module>
    main()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/spuder/Code/github/Ankermgmt/ankermake-m5-protocol/./ankerctl.py", line 337, in config_import
    config = cli.config.load_config_from_api(auth_token, region, env.insecure)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/spuder/Code/github/Ankermgmt/ankermake-m5-protocol/cli/config.py", line 91, in load_config_from_api
    profile = ppapi.profile()
              ^^^^^^^^^^^^^^^
  File "/Users/spuder/Code/github/Ankermgmt/ankermake-m5-protocol/libflagship/httpapi.py", line 13, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/spuder/Code/github/Ankermgmt/ankermake-m5-protocol/libflagship/httpapi.py", line 90, in profile
    return self._get("/profile", headers={"X-Auth-Token": self._auth})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/spuder/Code/github/Ankermgmt/ankermake-m5-protocol/libflagship/httpapi.py", line 33, in wrapper
    raise ValueError(f"API request failed: {data.status_code} {data.reason}")
ValueError: API request failed: 401 Unauthorized

Theories

I haven't opened the anker slicer in a couple of days/weeks. Maybe my credentials expired?

spuder commented 1 year ago

Opening the slicer shows this error, which seems to indicate that ankerctl can't handle when reauthentication is required

Screen Shot 2023-04-02 at 10 46 38 PM
chrivers commented 1 year ago

Yes, indeed.

Another issue is having to enter a CAPTCHA if you try to login too many times in a row (even if successful), which is also very hard to handle in a CLI tool.

I'll add some exception handling to this at some point, to give it a better presentation.

spuder commented 1 year ago

Confirmed more elegant handling of when login.json is absent (78e6996c5b13d9183568ff4fa7a937f5c92fa113)

mv ~/Library/Application\ Support/AnkerMake/AnkerMake_64bit_fp/login.json ~/Library/Application\ Support/AnkerMake/AnkerMake_64bit_fp/login.json.bak
./ankerctl.py config import
This platform does not support autodetection. Please specify file location