8.47. requests 模块 API 文档
8.47.1. API
8.47.1.1. class Response(_requests.Response):
def __init__(self):...
def _append_params_to_url(rqst:Response,url:str,params:dict)->int:...
def _append_headers(rqst:Response,headers:dict)->int:...
def request(method:str,url:str,params=None,headers=None,timeout=0.0,files=None,json=None,data=None)->Response:...
初始化请求对象,分配内存和固定请求头
def get(url:str,params=None)->Response:...
8.47.2. Examples
8.47.2.1. post_data.py
import requests
form_data = '------WebKitFormBoundaryrEPACvZYkAbE4bYB\r\nContent-Disposition: form-data; name="file"; filename="test_file.txt"\r\nContent-Type: text/plain\r\n\r\nhello, pikascript!\r\n------WebKitFormBoundaryrEPACvZYkAbE4bYB\r\nContent-Disposition: form-data; name="id"\r\n\r\n1670666272201\r\n------WebKitFormBoundaryrEPACvZYkAbE4bYB\r\nContent-Disposition: form-data; name="uploadFileNum"\r\n\r\n1\r\n------WebKitFormBoundaryrEPACvZYkAbE4bYB--\r\n'
header = {"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryrEPACvZYkAbE4bYB"}
a = requests.request("POST", "http://httpbin.org/post",
headers=header, data=form_data)
# a = requests.request("POST", "http://pikascript.com/uploads",
# headers=header, data=form_data)
print(a.headers)
print(a.content_length)
print(a.text)
8.47.2.2. get_basic.py
import requests
b = "kkk"
a = requests.request("GET", "http://pikapython.com/packages", params = {"name":"get-test"})
print(a.headers)
print(a.content_length)
print(a.text)
8.47.2.3. requests_encode.py
import requests
a = requests.request("GET", "http://pikascript.com/")
print(a.headers)
print(a.content_length)
print(a.text)
8.47.2.4. gitee_issue.py
import requests
a = requests.request("GET", "http://pikascript.com/pullrequest", params = {"json":'{"stepIndex":4,"packageName":"None","id":1669300904995,"version":"v1234.4321.1","releases":[],"fileList":[],"userEmail":"test@pikascript.com","userName":"pikascript","pullrequestOK":false,"pullrequestUrl":"","uploadFileNum":1}'})
print(a.headers)
print(a.content_length)
print(a.text)