我是 python 请求的新手,不知道如何使用发布请求调用此 API。这是我得到的信息:
POST /whatcaristhat?key=<CarsXE_API_Key> HTTP/1.1
Host: http://api.carsxe.com
Content-Type: text/plain
https://upload.wikimedia.org/wikipedia/commons/4/44/2019_Acura_RDX_A-Spec_front_red_4.2.18.jpg
到目前为止我得到的是:
import requests
api_key = 12345
url = f'http://api.carsxe.com/whatcaristhat?key={api_key}'
data = b'https://upload.wikimedia.org/wikipedia/commons/4/44/2019_Acura_RDX_A-Spec_front_red_4.2.18.jpg'
headers = {'Content-Type' : 'text/plain'}
r = requests.post(url,
data=data,
headers=headers)
print(r.status_code)
但我收到此错误:TypeError: a bytes-like object is required, not 'str'