WorkerJS_CloudFlare_ImageBed/python-uploader/test-tgph.py
BlueSkyXN 233d20e803 0.8.4
修复tgph
2024-09-12 22:30:16 +08:00

38 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import requests
# 图片上传接口的URL与JS代码中一致
upload_url = "https://telegra.ph/upload?source=bugtracker"
# 要上传的图片路径
image_path = r"F:\Download\20240707-204330.jpg"
# 读取图片文件
with open(image_path, 'rb') as image_file:
# 使用 multipart/form-data 发送文件
files = {
'file': image_file
}
# 向接口发送POST请求
response = requests.post(upload_url, files=files)
# 打印响应状态码和内容
print(f"状态码: {response.status_code}")
print(f"响应内容: {response.text}")
# 检查响应
if response.status_code == 200:
try:
result = response.json()
print(f"完整的JSON响应: {result}")
if isinstance(result, list) and result and 'src' in result[0]:
# 拼接图片的URL
image_url = f"https://telegra.ph{result[0]['src']}"
print(f"Image uploaded successfully: {image_url}")
else:
print(f"Unexpected response format: {response.text}")
except ValueError:
print(f"Failed to parse JSON response: {response.text}")
else:
print(f"Error uploading image: {response.status_code} - {response.text}")