[SOLVED] urllib.parse: MemoryError: memory allocation failed, allocating 560 bytes


  • Pybytes Beta

    Getting this error when I import uPython's urllib.

    >>> import urllib.parse
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    MemoryError: memory allocation failed, allocating 560 bytes
    >>>
    

    Best I can tell it's generating the error on line 475 where _hextobyte is created.

    Does it work for you? I have a WiPy 2.0, using the latest firmware.


  • Pybytes Beta

    @livius Yes this is a fresh boot with nothing in boot.py or main.py, no extra code is running. Even importing just the requested module still blows up memory.

    >>> import gc;gc.mem_free()
    65056
    >>> from urllib.parse import unquote
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/flash/lib/urllib/parse.py", line 475, in <module>
      File "/flash/lib/urllib/parse.py", line 475, in <dictcomp>
    MemoryError: memory allocation failed, allocating 2344 bytes
    >>>
    

    All is good though. I found a module written for WiPy 1.0 that has worked around the memory issues. The problem still needs to be fixed in uPython mainline libraries, but this workaround works for me.

    >>> from urllib import unquote
    >>> unquote('abc%20def')
    'abc def'
    >>>
    


  • @BetterAuto
    You have not enough memory
    Did you tested this after "fresh" reboot without any other your code?
    I do not like when libs import whole units
    e.g. import math can eat near to whole memory
    but better is to do e.g.
    from math import sin,cos,pi

    You can try to modify imports used in urllib - and you will see if it solve your problem


Log in to reply
 

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.