Create Image Upload is broken for Sync and Async
まだ誰も着手していません。
評価
調査の方向性
まず 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分
- マージ済み PR(30日)
- 1
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
cloudflare/cloudflare-python#2745 · コメント 2 件 ·
cloudflare/cloudflare-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
PedestrianDynamics/pyFDS-Evac#199 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
521xueweihan/HelloGitHub#3790 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
sandialabs/atlas-ui-3#978 ·
メンテナーはふだん 1 日以内に返信
-
area: tests perceived difficulty: 2
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Nitjsefnie-Harness-Commons/daedalus#1255 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
EleutherAI/lm-evaluation-harness#4256 ·
メンテナーはふだん 1 日以内に返信