Create Image Upload is broken for Sync and Async
还没有人认领这个 Issue。
评估
调研方向
先从 Cloudflare 和 AsyncCloudflare 客户端的 images.v1.create 开始,然后检查 tests/api_resources/images/test_v1.py 中链接覆盖率附近的内容。使用为 WebP 文件展示的元组重现 multipart 上传,并在请求能够接受该上传且不再出现表单字段解析错误后,为同步和异步情况添加覆盖率。
由索引模型根据 Issue 内容生成。
描述
Confirm this is a Python library issue and not an underlying Cloudflare API issue.
- This is an issue with the Python library
Describe the bug
The Cloudflare Image Create function is broken.
There is an example below, this has also been discussed on StackOverflow
I cant see any test coverage for this use case.
To Reproduce
This is a working example using Python Requests
import requests
with open(
"water bottle.webp", "rb"
) as f:
data = f.read()
# try requests
files = {
"file": (
"water bottle.webp",
data,
"image/webp",
)
}
response = requests.post(
url=f"https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/images/v1",
headers={
"Authorization": f"Bearer ..."
},
files=files,
)
print(response.status_code)
print(response.json())
This is a broken example using the Cloudflare Sync function
with open(
"water bottle.webp", "rb"
) as f:
data = f.read()
from cloudflare import Cloudflare
client = Cloudflare(
api_token='...'
)
# Create a tuple: (filename, binary data, content type)
file_tuple = ("water bottle.webp", data, "image/webp",)
cloudflare_image = await client.images.v1.create(
account_id=CLOUDFLARE_ACCOUNT_ID,
file=file_tuple,
)
print(cloudflare_image)
The output is
cloudflare.BadRequestError: Error code: 400 - {'result': None, 'success': False, 'errors': [{'code': 5400, 'message': 'Bad request: Error parsing form fields'}], 'messages': []}
This is a broken example using the Async Cloudflare function
from cloudflare import AsyncCloudflare
client = AsyncCloudflare(
api_token='...'
)
# Create a tuple: (filename, binary data, content type)
file_tuple = ("water bottle.webp", data, "image/webp",)
cloudflare_image = await client.images.v1.create(
account_id=CLOUDFLARE_ACCOUNT_ID,
file=file_tuple,
)
print(cloudflare_image)
The output is
cloudflare.BadRequestError: Error code: 400 - {'result': None, 'success': False, 'errors': [{'code': 5400, 'message': 'Bad request: Error parsing form fields'}], 'messages': []}
Code snippets
OS
macOS
Python version
3.12.9
Library version
v4.1.0
- 主要语言
- Python
- 星标
- 509
- 派生
- 150
- 平均合并
- 3 小时 15 分钟
- 30 天内合并 PR
- 1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
cloudflare/cloudflare-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
cloudflare/cloudflare-python#2747 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
cloudflare/cloudflare-python#2718 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
cloudflare/cloudflare-python#2692 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
cloudflare/cloudflare-python#2679 · 4 条评论 · 5 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 35/100
cloudflare/cloudflare-python#2745 · 1 条评论 ·
查看 cloudflare/cloudflare-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 86/100
EleutherAI/lm-evaluation-harness#4207 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
ClickHouse/clickhouse-connect#1057 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 2/5 1-3 小时 新手友好度 70/100
open-telemetry/sig-end-user#406 ·
-
bug ci good first issue
难度 2/5 1-3 小时 新手友好度 88/100