如何使用python从API获取数据

我必须使用python从rest api获取数据。如何发送标头以从API检索数据。是否有用于从API请求数据的模块。

评论
请勿打扰
请勿打扰

Yes python has requests lib to make a call to POST and GET methods

例如

import requests

url = 'web address'
params = {'key':'value'}
r = requests.get(url = URL, params = PARAMS) 
response = r.json() 
点赞
评论
雅典娜
雅典娜

Try requests it has two method get() and post()

请试试:

import requests
import json 
res = requests.get('paste your link here')
response = json.loads(res.text)
点赞
评论