慕的地8271018
2022-12-20 16:22:55
我想使用請求庫向特定網頁http://latex2png.com/api/convert發出請求,以便將一些乳膠轉換為 PNG 圖像。但是,我不確定該網站接受哪些數據參數。有什么方法可以使用requests庫來查看需要滿足哪些參數?我試過跑步options = { "auth": {"user": "guest", "password": "guest"}, "latex": '$a^3$', "resolution": 900, "color": "969696",}r = requests.post('http://latex2png.com/api/convert')print(r.content)但我明白了b'{"result-message":"no request","result-code":-2}'。沒有關于此特定 API 和網站的文檔或在線幫助。
1 回答

白板的微信
TA貢獻1883條經驗 獲得超3個贊
那是因為你發帖的方式不對,試試這個:
import requests
headers = {
"Content-type": "application/x-www-form-urlencoded",
}
data = {
"auth": {
"user": "guest",
"password": "guest"
},
"latex": "a^3",
"resolution": 600,
"color": "969696"
}
r = requests.post('http://latex2png.com/api/convert', headers=headers, json=data) # the right way to send POST requests
print(r.json()) # print the json
image_url = "http://latex2png.com" + r.json()['url']
r = requests.get(image_url)
with open("download.png", "wb+") as f: # download it.
f.write(r.content)
添加回答
舉報
0/150
提交
取消