Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
emix1984 opened this issue Apr 4, 2024 · 1 comment

Comments

@emix1984
Copy link

emix1984 commented Apr 4, 2024

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

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

@icret
Copy link
Owner

icret commented Apr 6, 2024

使用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}.")

@icret icret closed this as completed Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants