icret / EasyImages2.0

简单图床 - 一款功能强大无数据库的图床 2.0版

Home Page:https://png.cm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

API说明文档中python示例测试不成功,payload参数应该怎么设定?

emix1984 opened this issue · comments

我尝试着使用python 实现API token批量上传图片到图床。
参考了提供的api使用文档
https://github.com/icret/EasyImages2.0/blob/master/docs/API.md

其中测试了《Python示例》部分的代码,无法成功导入payload部分和headers部分。
不知道可否给予一个比较清晰的payload入参的变量和对应参数的格式。
感激不尽。

使用AI提供的代码方便你调试

  • 代码一
import requests

url = "http://127.0.0.1/api/index.php"
token = "YOUR_TOKEN_HERE"  # Replace with your actual token
image_path = "path/to/your/image.jpg"  # Replace with the path to your image file

files = {
  "image": open(image_path, "rb")
}

data = {
  "token": token
}

response = requests.post(url, files=files, data=data)

print(response.text)
  • 代码二
import requests

# 本地图片文件路径
image_path = "/path/to/your/image.jpg"

# token值,需从实际来源获取(例如读取tokenList文件)
token = "your_token_value_here"

# 目标URL
url = "http://127.0.0.1/api/index.php"

# 构建请求参数
files = {'image': open(image_path, 'rb')}
data = {'token': token}

# 发送POST请求
response = requests.post(url, files=files, data=data)

# 检查响应状态码
if response.status_code == 200:
    print("Upload successful.")
else:
    print(f"Upload failed with status code {response.status_code}.")