scientifichackers / ampy

MicroPython Tool - Utility to interact with a MicroPython board over a serial connection.
MIT License
723 stars 157 forks source link

GET fails with CircuitPython #110

Open jerryneedell opened 2 years ago

jerryneedell commented 2 years ago

The "get" command imports ubinascii but CircuitPython now uses binascii, so it fails with:

jerryneedell@jerryneedell-ubuntu-macmini:~/projects/microbit_v2$ ampy get code.py
Traceback (most recent call last):
  File "/home/jerryneedell/.local/bin/ampy", line 8, in <module>
    sys.exit(cli())
  File "/home/jerryneedell/.local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/jerryneedell/.local/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/jerryneedell/.local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/jerryneedell/.local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/jerryneedell/.local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/jerryneedell/.local/lib/python3.8/site-packages/ampy/cli.py", line 126, in get
    contents = board_files.get(remote_file)
  File "/home/jerryneedell/.local/lib/python3.8/site-packages/ampy/files.py", line 82, in get
    raise ex
  File "/home/jerryneedell/.local/lib/python3.8/site-packages/ampy/files.py", line 74, in get
    out = self._pyboard.exec_(textwrap.dedent(command))
  File "/home/jerryneedell/.local/lib/python3.8/site-packages/ampy/pyboard.py", line 279, in exec_
    raise PyboardError('exception', ret, ret_err)
ampy.pyboard.PyboardError: ('exception', b'', b'Traceback (most recent call last):\r\n  File "<stdin>", line 3, in <module>\r\nImportError: no module named \'ubinascii\'\r\n')

this can be fixed by modifying files.py at line 62 to replace import ubinascii with

            try:
                import ubinascii
            except:
                import binascii as ubinascii

with this change:

jerryneedell@jerryneedell-ubuntu-macmini:~/projects/microbit_v2$ ampy get code.py
print("Hello World!")