[H-GEN] Micropython help

Stephen Thorne stephen at thorne.id.au
Fri Feb 9 20:02:33 AEST 2018


Looking at
https://github.com/micropython/micropython-lib/blob/master/urequests/urequests.py
it
looks like you have to use the API in a weird way:

r = urequests.get(url)

BLOCK_SIZE = 8192 # tune as appropriate
output = open('outputfile', 'w')
while True:
  block = r.raw.read(BLOCK_SIZE)
  if block == '':  # empty read means the end.
    break
  output.write(block)
output.close()
r.close()

That while loop exists in python core, it's called
shutil.copyfileobj(r.raw, output)
https://github.com/python/cpython/blob/master/Lib/shutil.py

On Fri, 9 Feb 2018 at 03:57 Russell Stuart <russell-humbug at stuart.id.au>
wrote:

> [ Humbug *General* list - semi-serious discussions about Humbug and     ]
> [ Unix-related topics. Posts from non-subscribed addresses will vanish. ]
>
> On Fri, 2018-02-09 at 10:12 +1000, Scott Wilson wrote:
> > I'm messing around with a work project using Micropython on an ESP32
> > (specifically, the fipy from pycom - https://pycom.io/product/fipy/)
> > and I've hit a snag. I need to pull a large (well, large for
> > micropython - ~70Mb) file over HTTP and write it to the SD card.
>
> Doing it using raw sockets isn't hard.  Bring it along to Humbug.
> _______________________________________________
> General mailing list
> General at lists.humbug.org.au
> http://lists.humbug.org.au/mailman/listinfo/general
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.humbug.org.au/pipermail/general/attachments/20180209/893b0d37/attachment.html>


More information about the General mailing list