Logo
master
  • mPython Board Contents

mPython Board Tutorial

  • Basic Tutorials
  • Advance Tutorials
  • Get Started - Coding Example

MicroPython Library

  • Python Standard library
  • MicroPython Class Library

mPython Library

  • mPython Library
    • mpython — mPython Board related built-in functions
    • music — Music related functions
    • urequests — Related functions of HTTP client
      • Response class
        • Method
      • Method
    • umqtt.simple — MQTT client function
    • gui — Provide related functions of GUI class drawing
    • audio — Provide audio playback related functions
    • radio — Radio-related functions
    • sdcard — SD Card
    • bluebit — blue:bit driver
    • parrot — mPython Expansion Board driver
    • ds18x20 — ds18b20 Temperature sensor driver
    • servo — Servo driver function
  • mPython extend library

MicroPython Syntax

  • MicroPython syntax
  • Copyright
  • release

mPython Series

  • mPython Expansion Board
mPython board
  • Docs »
  • mPython Library »
  • urequests — Related functions of HTTP client
  • Edit on GitHub

urequests — Related functions of HTTP client¶

Before we used the socket library, this tool as a primer is still good, for understanding the basic concepts of some crawlers, its helpful to master it. After get started, we need to learn some more advanced content and tools to facilitate our crawling. Then this section briefly introduces the basic usage of urequests library.

Response class¶

class urequests.Response(s)¶

The Response class object contains the server’s response to the HTTP request.

  • s-ussl object

Method¶

urequests.close()¶

Shutdown socket。

@urequests.content¶

Returns the content of the response, in bytes.

@urequests.text¶

Return the content of the response as text, encoded as unicode.

urequests.json()¶

Return response json encoded content and convert to dict type.

Method¶

urequests.request(method, url, data=None, json=None, headers={}, params=None, files=None)¶

Send an HTTP request to the server.

  • method - HTTP method to use
  • url - URL to send
  • data - To append to the body of the request. If a dictionary or tuple list is provided, the form will be encoded.
  • json - json is used to attach to the body of the request.
  • headers - Dictionary of headers to send.
  • params - URL parameters attached to the URL. If a dictionary or tuple list is provided, the form will be encoded.
  • files - Used for file upload, the type is 2-tuple, which defines the file name, file path and content type. As follows,{‘name’, (file directory,content-type)}
urequests.head(url, **kw)¶

Send HEAD request and return Response object.

  • url - Request object URL
  • **kw - The parameters of the request method.
urequests.get(url, **kw)¶

Send GET request and return Response object.

  • url - Request object URL
  • **kw - Parameters of request method.
urequests.post(url, **kw)¶

Send POST request and return Response object.

  • url - Request object URL
  • **kw - Parameters of request method.
urequests.put(url, **kw)¶

Send PUT request and return Response object.

  • url - RRequest object URL
  • **kw - Parameters of request method.
urequests.patch(url, **kw)¶

Send PATCH request, return Response object.

  • url - Request object URL
  • **kw - Parameters of request method.
urequests.delete(url, **kw)¶

Send a DELETE request. Return Response object。

  • url - Request object URL
  • **kw - Parameters of request method.
requests example¶
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import urequests
from mpython import *

#连接网络
my_wifi = wifi()
my_wifi.connectWiFi('', '')

# 访问ip地址 api
r = requests.get("http://ip-api.com/json/")
print(r)
print(r.content)  # 返回响应的内容
print(r.text)  # 以文本方式返回响应的内容
print(r.content)
print(r.json())  # 返回响应的json编码内容并转为dict类型

# It's mandatory to close response objects as soon as you finished
# working with them. On MicroPython platforms without full-fledged
# OS, not doing so may lead to resource leaks and malfunction.
r.close()
Next Previous

© Copyright 2018-2022 labplus.All Rights Reserved Revision 5e1f93ed.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: master
Versions
master
latest
v2.2.1
Downloads
html
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.