Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

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

    Scheduled Pinned Locked Moved Getting Started
    error
    3 Posts 2 Posters 1.7k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B Offline
      BetterAuto Pybytes Beta
      last edited by BetterAuto

      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.

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @BetterAuto
        last edited by

        @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

        think about people first, then computers

        B 1 Reply Last reply Reply Quote 0
        • B Offline
          BetterAuto Pybytes Beta @livius
          last edited by

          @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'
          >>>
          
          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom