{ "cells": [ { "cell_type": "markdown", "id": "acb97724-2696-409c-b7bd-f7d1d7f8453a", "metadata": {}, "source": [ "# Requests\n", "\n", "For downloading web content, Python features the [`requests`](https://docs.python-requests.org/en/master/user/quickstart/) library. MicroPython `urequests` implements a subset of this library. Let's download it." ] }, { "cell_type": "code", "execution_count": 7, "id": "aad16dc5-e4a7-4a99-a894-61c34451db44", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[0m\u001b[0m\u001b[46m\u001b[30mConnected to esp32 @ serial:///dev/ttyUSB0\u001b[0m\n", "\u001b[0mInstalling micropython-urequests 0.6 from https://micropython.org/pi/urequests/urequests-0.6.tar.gz\n", "\u001b[0m\u001b[34mUPDATE /lib/urequests.py\n", "\u001b[0m\u001b[0m" ] } ], "source": [ "%connect esp32\n", "%upip -t internet/code/lib install urequests\n", "%rsync" ] }, { "cell_type": "markdown", "id": "f9762039-b02a-476b-b76b-7106507270b4", "metadata": {}, "source": [ "Fetch a sample webpage:" ] }, { "cell_type": "code", "execution_count": 8, "id": "628875b6-515b-484a-9848-1001ca5c2db5", "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true }, "tags": [ "hide-output" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[0m\n", "\n", "\n", "\n", "\n", "
\n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", "\n", " MicroPython is a lean and efficient implementation of the\n", " Python 3 programming language\n", " that includes a small subset of the Python standard library and is\n", " optimised to run on microcontrollers and in constrained environments.\n", "
\n", "\n", " The MicroPython pyboard is a compact electronic\n", " circuit board that runs MicroPython on the bare metal, giving you a low-level\n", " Python operating system that can be used to control all kinds of electronic\n", " projects.\n", "
\n", "\n", " MicroPython is packed full of advanced features such as an interactive\n", " prompt, arbitrary precision integers, closures, list comprehension,\n", " generators, exception handling and more. Yet it is compact enough to fit and\n", " run within just 256k of code space and 16k of RAM.\n", "
\n", "\n", " MicroPython aims to be as compatible with normal Python as possible to\n", " allow you to transfer code with ease from the desktop to a microcontroller\n", " or embedded system.\n", "
\n", "\n", " MicroPython is a full Python compiler and runtime that runs on the bare-metal.\n", " You get an interactive prompt (the REPL) to execute commands immediately,\n", " along with the ability to run and import scripts from the built-in filesystem.\n", " The REPL has history, tab completion, auto-indent and paste mode for a great\n", " user experience.\n", "
\n", "\n", " MicroPython strives to be as compatible as possible with normal Python (known\n", " as CPython) so that if you know Python you already know MicroPython. On the\n", " other hand, the more you learn about MicroPython the better you become at Python.\n", "
\n", "\n", " In addition to implementing a selection of core Python libraries, MicroPython\n", " includes modules such as "machine" for accessing low-level hardware.\n", "
\n", "\n", " MicroPython is written in C99 and the entire MicroPython core is\n", " available for general use under the very liberal\n", " MIT license.\n", " Most libraries and extension modules (some of which are from a third party) are\n", " also available under MIT or similar licenses.\n", "
\n", "\n", " You can freely use and adapt MicroPython for personal use, in education, and\n", " in commercial products.\n", "
\n", "\n", " MicroPython is developed in the open on GitHub and the source code is available\n", " at the GitHub page,\n", " and on the download page.\n", " Everyone is welcome to contribute to the project.\n", "
\n", "\n", " MicroPython employs many advanced coding techniques, and lots of tricks\n", " to maintain a compact size while still having a full set of features.\n", "
\n", "\n", " Some of the more notable items are:\n", "