adafruit_requests

A requests-like library for web interfacing

  • Author(s): ladyada, Paul Sokolovsky

Implementation Notes

Adapted from https://github.com/micropython/micropython-lib/tree/master/urequests

micropython-lib consists of multiple modules from different sources and authors. Each module comes under its own licensing terms. Short name of a license can be found in a file within a module directory (usually metadata.txt or setup.py). Complete text of each license used is provided at https://github.com/micropython/micropython-lib/blob/master/LICENSE

author=’Paul Sokolovsky’ license=’MIT’

Software and Dependencies:

class adafruit_requests.Response(sock)

The response from a request, contains all the headers/content

close()

Close, delete and collect the response data

content

The HTTP content direct from the socket, as bytes

iter_content(chunk_size=1, decode_unicode=False)

An iterator that will stream data by only reading ‘chunk_size’ bytes and yielding them, when we can’t buffer the whole datastream

json()

The HTTP content, parsed into a json dictionary

text

The HTTP content, encoded into a string according to the HTTP header encoding

adafruit_requests.delete(url, **kw)

Send HTTP DELETE request

adafruit_requests.get(url, **kw)

Send HTTP GET request

adafruit_requests.head(url, **kw)

Send HTTP HEAD request

adafruit_requests.parse_headers(sock)

Parses the header portion of an HTTP request/response from the socket. Expects first line of HTTP request/response to have been read already return: header dictionary rtype: Dict

adafruit_requests.patch(url, **kw)

Send HTTP PATCH request

adafruit_requests.post(url, **kw)

Send HTTP POST request

adafruit_requests.put(url, **kw)

Send HTTP PUT request

adafruit_requests.request(method, url, data=None, json=None, headers=None, stream=False, timeout=1)

Perform an HTTP request to the given url which we will parse to determine whether to use SSL (‘https://’) or not. We can also send some provided ‘data’ or a json dictionary which we will stringify. ‘headers’ is optional HTTP headers sent along. ‘stream’ will determine if we buffer everything, or whether to only read only when requested

adafruit_requests.set_socket(sock, iface=None)

Helper to set the global socket and optionally set the global network interface. :param sock: socket object. :param iface: internet interface object