簡體   English   中英

如何將cURL請求轉換為Python請求

[英]How to convert a cURL request to Python request

我有一個cURL請求正常工作。

curl http://localhost:5000/models/images/generic/infer.json -XPOST -F job_id='123' -F dont_resize='dont_resize' -F snapshot_epoch='100' -F image_file='@/home/hellouser/Downloads/infer/Users/User01/Images/tiles/999/00.jpg'`

我有一個python腳本,我想執行相同的請求。 但我得到以下錯誤,

{“error”:{“message”:“'NoneType'對象沒有屬性'iteritems'”,“type”:“AttributeError”}}

這是python代碼,

import requests
data = {
    'job_id': '123',
    'dont_resize': 'dont_resize',
    'snapshot_epoch': '100',
    'image_file': '@/home/hellouser/Downloads/infer/Users/User01/Images/tiles/999/00.jpg'    }

url = 'http://localhost:5000/models/images/generic/infer.json'
r = requests.post(url=url, data=data)

知道如何正確轉換代碼嗎? 我應該在請求中傳遞file=file嗎?

嘗試這個:

data = {
    'job_id': '123',
    'dont_resize': 'dont_resize',
    'snapshot_epoch': '100',
}
files = {
    'image_file': open('/home/hellouser/Downloads/infer/Users/User01/Images/tiles/999/00.jpg', 'rb')
}

url = 'http://localhost:5000/models/images/generic/infer.json'
r = requests.post(url=url, data=data, files=files)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM