第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用請(qǐng)求將 cURL 轉(zhuǎn)換為 Python

使用請(qǐng)求將 cURL 轉(zhuǎn)換為 Python

我在使用 Python 訪問(wèn) API 時(shí)遇到問(wèn)題。這是我的 Python:import requestsurl = 'https://bigjpg.com/api/task/'payload = {'style': 'photo', 'noise': '3', 'x2': '1', 'input': 'https://www.example.com/photo.jpg'}headers = {'X-API-KEY': 'xyz123'}r = requests.get(url, data=payload, headers=headers)print(r.text)它返回 404 內(nèi)容,但是當(dāng)我使用 cURL 時(shí),它可以工作并返回我正在尋找的 json。這是 API 中的 cURL 行:curl -F 'conf={"style": "photo", "noise": "3", "x2": "1", "input": "https://www.example.com/photo.jpg"}' -H 'X-API-KEY:xyz123' https://bigjpg.com/api/task/
查看完整描述

2 回答

?
猛跑小豬

TA貢獻(xiàn)1858條經(jīng)驗(yàn) 獲得超8個(gè)贊

您的問(wèn)題是 cURL 行上傳遞的內(nèi)容是confJSON 對(duì)象的分配對(duì)象,但是您將 Python dict 傳遞給data.


這應(yīng)該有效:


import requests


url = 'https://bigjpg.com/api/task/'

payload = 'conf={"style": "photo", "noise": "3", "x2": "1", "input": "https://www.example.com/photo.jpg"}'

headers = {'X-API-KEY': 'xyz123'}


r = requests.post(url, data=payload, headers=headers)


print(r.text)

正如@Laurent Brisiel 所說(shuō),您需要發(fā)布而不是獲取。


如果你更喜歡使用 Python 字典,你也可以這樣做:


import requests

import json


url = 'https://bigjpg.com/api/task/'

conf = {'style': 'photo', 'noise': '3', 'x2': '1', 'input': 'https://www.example.com/photo.jpg'}

payload = f'conf={json.dumps(conf)}'

headers = {'X-API-KEY': 'xyz123'}


r = requests.post(url, data=payload, headers=headers)


print(r.text)


查看完整回答
反對(duì) 回復(fù) 2022-07-12
?
aluckdog

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超7個(gè)贊

a 的等價(jià)物curl -F是 POST 而不是 GET:

r = requests.post(url, data=payload, headers=headers)


查看完整回答
反對(duì) 回復(fù) 2022-07-12
  • 2 回答
  • 0 關(guān)注
  • 188 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)