【发布时间】:2021-03-27 17:40:24
【问题描述】:
我想使用 Python 下载带有 Pexels API (documentation) 的图像。首先,我通过以下方式获取图片的 ID:
import requests
image_base_url = 'https://api.pexels.com/v1/search'
api_key = 'my_api_key'
my_obj = {'query':'Stock market'}
x = requests.get(image_base_url,headers = {'Authorization':api_key},data = my_obj)
print(x.text)
然后,我为我想要的图像获取一个 ID 并运行它:
photo_request_link = 'https://api.pexels.com/v1/photos/'
photo_id = {'id':159888}
final_photo = requests.get(photo_request_link,headers = {'Authorization':api_key},data=photo_id)
print(final_photo)
但结果是 404 错误。知道为什么吗?
【问题讨论】:
标签: python python-3.x api python-requests