WorkerJS_CloudFlare_ImageBed/python-uploader/test-tencent.py
BlueSkyXN 7fb7a7a914 0.9.16
tx接口挂了,前端下掉。然后对ipfs-fix.js新增多个ipfs网关,不过他们的可用性不高
2024-10-01 19:13:29 +08:00

32 lines
1010 B
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
upload_url = "https://openai.weixin.qq.com/weixinh5/webapp/h774yvzC2xlB4bIgGfX2stc4kvC85J/cos/upload"
# 图片路径
image_path = r"F:\Download\ecabfc9aa7dace978229f8563ab5c856fe530eea.jpg"
# 准备上传的文件,模拟 PHP 中的 `CURLFile`,用 `files` 参数传递文件
files = {
'media': ('ecabfc9aa7dace978229f8563ab5c856fe530eea.jpg', open(image_path, 'rb'), 'image/jpeg')
}
# 发送POST请求上传图片
try:
response = requests.post(upload_url, files=files)
response.raise_for_status() # 检查请求是否成功
# 解析响应数据
response_data = response.json()
if 'url' in response_data:
print("图片上传成功访问URL为", response_data['url'])
else:
print("上传失败服务器未返回URL:", response_data)
print(response)
except requests.exceptions.RequestException as e:
print(f"图片上传失败: {e}")
finally:
# 关闭文件
files['media'][1].close()