PlatformIO Community

Pio run failed : AttributeError: type object 'array.array' has no attribute 'tostring'

Hello everyone,

Today I updated vscode and pio.
After the update I tried to build my project but it won’t run the build script :

Executing task in folder ENI-Logger: pio run <

Processing disco_f746ng (platform: ststm32; board: disco_f746ng; framework: mbed)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/disco_f746ng.html
PLATFORM: ST STM32 (10.0.1) > ST 32F746GDISCOVERY
HARDWARE: STM32F746NGH6 216MHz, 320KB RAM, 1MB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, cmsis-dap, jlink)
PACKAGES:

  • framework-mbed 6.60200.200722 (6.2.0)
  • toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
    AttributeError: type object ‘array.array’ has no attribute ‘tostring’:
    File “/home/mathieu-ledimna/.platformio/penv/lib/python3.9/site-packages/platformio/builder/main.py”, line 170:
    env.SConscript("$BUILD_SCRIPT")
    File “/home/mathieu-ledimna/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Script/SConscript.py”, line 598:
    return _SConscript(self.fs, *files, **subst_kw)
    File “/home/mathieu-ledimna/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Script/SConscript.py”, line 287:
    exec(compile(scriptdata, scriptname, ‘exec’), call_stack[-1].globals)
    File “/home/mathieu-ledimna/.platformio/platforms/ststm32/builder/main.py”, line 99:
    target_elf = env.BuildProgram()
    File “/home/mathieu-ledimna/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Environment.py”, line 219:
    return self.method(*nargs, **kwargs)
    File “/home/mathieu-ledimna/.platformio/penv/lib/python3.9/site-packages/platformio/builder/tools/platformio.py”, line 61:
    env.ProcessProgramDeps()
    File “/home/mathieu-ledimna/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Environment.py”, line 219:
    return self.method(*nargs, **kwargs)
    File “/home/mathieu-ledimna/.platformio/penv/lib/python3.9/site-packages/platformio/builder/tools/platformio.py”, line 127:
    env.BuildFrameworks(env.get(“PIOFRAMEWORK”))
    File “/home/mathieu-ledimna/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Environment.py”, line 219:
    return self.method(*nargs, **kwargs)
    File “/home/mathieu-ledimna/.platformio/penv/lib/python3.9/site-packages/platformio/builder/tools/platformio.py”, line 342:
    SConscript(env.GetFrameworkScript(f), exports=“env”)
    File “/home/mathieu-ledimna/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Script/SConscript.py”, line 661:
    return method(*args, **kw)
    File “/home/mathieu-ledimna/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Script/SConscript.py”, line 598:
    return _SConscript(self.fs, *files, **subst_kw)
    File “/home/mathieu-ledimna/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Script/SConscript.py”, line 287:
    exec(compile(scriptdata, scriptname, ‘exec’), call_stack[-1].globals)
    File “/home/mathieu-ledimna/.platformio/platforms/ststm32/builder/frameworks/mbed.py”, line 35:
    SConscript(
    File “/home/mathieu-ledimna/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Script/SConscript.py”, line 661:
    return method(*args, **kw)
    File “/home/mathieu-ledimna/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Script/SConscript.py”, line 598:
    return _SConscript(self.fs, *files, **subst_kw)
    File “/home/mathieu-ledimna/.platformio/packages/tool-scons/scons-local-4.0.1/SCons/Script/SConscript.py”, line 287:
    exec(compile(scriptdata, scriptname, ‘exec’), call_stack[-1].globals)
    File “/home/mathieu-ledimna/.platformio/packages/framework-mbed/platformio/platformio-build.py”, line 43:
    from pio_mbed_adapter import PlatformioMbedAdapter
    File “/home/mathieu-ledimna/.platformio/packages/framework-mbed/platformio/pio_mbed_adapter.py”, line 23:
    from tools.build_api import prepare_toolchain, UPDATE_WHITELIST
    File “/home/mathieu-ledimna/.platformio/packages/framework-mbed/tools/build_api.py”, line 37:
    from .utils import (mkdir, run_cmd, run_cmd_ext, NotSupportedException,
    File “/home/mathieu-ledimna/.platformio/packages/framework-mbed/tools/utils.py”, line 33:
    from intelhex import IntelHex
    File “/home/mathieu-ledimna/.platformio/packages/framework-mbed/platformio/package_deps/py3/intelhex/init.py”, line 44:
    from intelhex.compat import (
    File “/home/mathieu-ledimna/.platformio/packages/framework-mbed/platformio/package_deps/py3/intelhex/compat.py”, line 60:
    array_tobytes = getattr(array.array, “tobytes”, array.array.tostring)
    ================================================= [FAILED] Took 0.39 seconds =================================================
    The terminal process “pio ‘run’” terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

Has anyone got this type of error ?

It seems to be linked to the mbed framework.
I tried to create an Arduino project and it worked…

Even if I try to create a new mbed-based project, the project creator returns an error

The problem was from the mbed framework :

.platformio/packages/framework-mbed/platformio/package_deps/py3/intelhex/compat.py", line 60

Change array_tobytes = getattr(array.array, “tobytes”, array.array.tostring)
To array_tobytes = getattr(array.array, “tobytes”, array.array.tobytes)

The tostring attribute is deprecated since python 3.9