首先,需要使用 Python 的 requests
模块来发送 HTTP 请求。
首先安装 requests
模块:
pipinstall requests
然后就可以使用以下代码来上传图片了:
import requests
# 要上传的图片文件的路径
file_path = '/path/to/image.jpg'
# 设置要上传的文件的参数名称,一般为 'file'
file_param_name = 'file'
# 设置要发送的请求的 URL
url = 'http://example.com/upload'
# 读取图片文件内容
with open(file_path, 'rb'