Skip to content

requests

Boris Lovosevic edited this page Jul 30, 2019 · 5 revisions

requests module



The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, where hypertext documents include hyperlinks to other resources that the user can easily access, for example by a mouse click or by tapping the screen in a web browser. HTTP was developed to facilitate hypertext and the World Wide Web.

requests module enables trasfering data between K210 MicroPython and the remote http server.

Features

  • GET, HEAD, POST, PUT, PATCH and DELETE methods are supported.
  • Using secured http (SSL/TLS) is supported (with WiFi interface only).
  • Flexible POST method supporting sending multipart data (from MicroPython dictionary) and Base-64 encoded data.
  • Status, headers and response data are provided as a result
  • Receiving response data into file is supported

Methods


All http methods returns the result in the form of 3-item tuple: (status, header, response).
status http operation result code
header string, http response headers
response bytearray, http response body
If response to file was requested, response will be the string "Saved to file '<file_name>', size=<file_size>".


requests.get(url [, file] [,bufsize])

Sends GET request to the server.

url string containing the server address and optional parameters.
file optional, string containing the file name to which to save the response bufsize optional, size of the temporary buffer used during transfer; default: 1536

Returns the result tuple.

requests.head(url)

Sends HEAD request to the server.

url string containing the server address and optional parameters.

Returns the result tuple. Only the status and header are returned.

requests.post(url, params [, args])

Argument Description
url string containing the server address, IP or domain name can be used
params POST request parameters
params can be string (only if multipart=False or dictionary
If multipart is False and params are distionary, the parameters will be url-encoded
Valid dictionary value that can be sent are: string, int, float or buffer object
file optional, file name to which to save the response to
Default: not used
multipart optional, if set to True sends the multipard data request
Default: False
If multipart is False, data are sent as "Content-Type: application/x-www-form-urlencoded"
If multipart is True, data are sent as "Content-Type: multipart/form-data"
base64 optional, if set to True sends the buffer object parameter from multipart parameters as base64 encoded
Default: False
bufsize optional, size of the temporary buffer used during transfer
Default: 1536

Clone this wiki locally