【发布时间】:2019-12-16 16:50:22
【问题描述】:
我有一个现有的 API,我使用 PHP 连接并发送图像,代码如下所示...
$url = 'https://example.com/api';
$ch = \curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Subscription-Key: 345sdf4'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "{
\"fileurl\":\"" . $this->_config['server_config']['server_url'] . $my_image . "\"
}");
我正在尝试将其转换为 Python3,我知道我需要 requests 所以到目前为止...
import requests
api_url_base = 'https://example.com/api'
headers = {'Content-Type': 'application/json',
'Subscription-Key': '345sdf4'}
但据我所知,如何添加图像?我已经知道图片的绝对路径了
【问题讨论】:
-
您的
POST正文将类似于json.dumps(dict({'fileurl': myUrl}))
标签: php python python-3.x