前言
… …
requests模块的使用
导入模块
pip3 install requests
获取数据,并写入json文件中
import requests
url = "http://192.168.1.241:8080/version"
get_api_data = requests.get(url).json()
data = get_api_data["data"]
return_data = json.dumps(data, ensure_ascii=False)
filePath = "/data/version.json"
with open(filePath, "w", encoding="utf-8") as fw:
json.dump(return_data, fw, ensure_ascii=False)
- ensure_ascii的值为False,不然中文会乱码
结语
Python’s Requests Library (Guide)
Making HTTP Requests With Python
Requests: HTTP for Humans
HTTP Request Methods
HTTP Requests With the “requests” Library Quiz
List of HTTP status codes