---
title: "mrequests - HTTP client module for MicroPython"
url: "https://maker.wiznet.io/viktor/projects/mrequests-http-client-module-for-micropython/"
markdown_url: "https://maker.wiznet.io/viktor/projects/mrequests-http-client-module-for-micropython/md"
type: "UCC: User Created Content"
author: "Christopher Arndt"
author_url: "https://github.com/SpotlightKid/mrequests/tree/master"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "Christopher Arndt"
original_url: "https://github.com/SpotlightKid/mrequests/tree/master"
published: "2023-09-20"
language: "en"
hardware: ["WIZnet W5500"]
likes: 0
views: 449
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# mrequests - HTTP client module for MicroPython

> HTTP client module for MicroPython

Original author: Christopher Arndt (source: https://github.com/SpotlightKid/mrequests/tree/master)

## Components

- **WIZnet W5500** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5500))

WIZnet parts: W5500 ([Datasheet](https://docs.wiznet.io/Product/Chip/Ethernet/W5500/datasheet?utm_source=maker&utm_medium=project&utm_campaign=w5500), [product hub](https://maker.wiznet.io/products/w5500/))

## Article

below description is copied from Github readme file. Link is given above.

## mrequests

An HTTP client module for MicroPython with an API *similar* to [requests](https://github.com/psf/requests).

This is an evolution of the [urequests](https://github.com/micropython/micropython-lib/blob/master/urequests/urequests.py) module from [micropython-lib](https://github.com/micropython/micropython-lib) with a few extensions and many fixes and convenience features.

## Features & Limitations

### Compatibility

Supports the unix, stm32, esp8266 and esp32 MicroPython ports as well as CPython.

On the unix, stm32 and esp8266 ports the SSL/TLS support has some limitations due to problems with MicroPython's `ssl` module on these platforms.

On the stm32 port installing a custom-compiled firmware with network/SSL support is required.

### Features

- Supports redirection with absolute and relative URLs (see below for details).

- Supports HTTP basic authentication (requires `ubinascii` module).

- Supports socket timeouts.

- Response headers can optionally be saved in the response object.

- Respects `Content-length` header in response.

- Supports responses with chunked transfer encoding.

- `Response` objects have a `save` method to save the response body to a file, reading the response data and writing the file in small chunks.

- The `Response` class for response objects can be substituted by a custom response class.

### Limitations

- `mrequests.request` is a synchroneous, blocking function.

- The code is *not* interrupt save and a fair amount of memory allocation is happening in the process of handling a request.

- URL parsing does not cover all corner cases (see [test_urlparse](https://github.com/SpotlightKid/mrequests/blob/master/tests/test_urlparse.py) for details).

- URLs with authentication credentials in the host part (e.g. `http://user:secret@myhost/`) are *not supported*. Pass authentication credentials separately via the `auth` argument instead.

- SSL/TLS support on the MicroPython *unix*, *stm32* and *esp8266* ports is limited. In particular, their `ssl` module does not support all encryption schemes commonly in use by popular servers, meaning that trying to connect to them via HTTPS will fail with various cryptic error messages.

- Request and JSON data may be passed in as bytes or strings and the request data will be encoded to bytes, if necessary, using the encoding given with the `encoding` parameter. But be aware that encodings other than `utf-8` are *not supported* by most (any?) MicroPython implementations.

- Custom headers may be passed as a dictionary with string or bytes keys and values and must contain only ASCII chars. If you need header values to use non-ASCII chars, you need to encode them according to RFC 8187.

- The URL and specifically any query string parameters it contains will not be URL-encoded, and it may contain only ASCII chars. Make sure you encode the query string part of the URL with `urlencode.quote` before passing it, if necessary.

- When encoding `str` instances via `urlencode.urlencode` or `urlencode.quote`, the `encoding` and `errors` arguments are currently ignored by MicroPython and it behaves as if their values were `"utf-8"` resp. `"ignore"`.

- In responses using "chunked" transfer-encoding, chunk extensions and trailers are ignored.

### Redirection Support

- Can follow redirects for response status codes 301, 302, 303, 307 and 308.

- The HTTP method is changed to `GET` for redirects, unless the original method was `HEAD` or the status code is 307 or 308.

- For status code 303, if the method of the request resulting in a redirection (which may have been the result of a previous redirection) is `GET`, the redirection is not followed, since the `Location` header is supposed to indicate a non-HTTP resource then.

- Redirects are allowed to change the protocol from `http` to `https`, but redirects changing from `https` to `http` will not be followed.

- The `request` function has an additional keyword argument `max_redirects`, defaulting to 1, which controls how many level of redirections are followed. If this is exceeded, the function raises a `ValueError`.

- The code does not check for infinite redirection cycles. It is advised to keep `max_redirects` to a low number instead.

---

Source: https://maker.wiznet.io/viktor/projects/mrequests-http-client-module-for-micropython/
