Urllib error when trying to use list inside a form-data
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 52/100
Rechercherichtung
Reproduziere den Fehler mit der bereitgestellten OpenAPI-Spezifikation und dem Beispiel unter Verwendung von ApiClient und DefaultApi.submit_post, mit Fokus auf SubmitPostRequestInput und der Verarbeitung von multipart/form-data. Verfolge die Serialisierung der generierten Anfrage bis in urllib3 und überprüfe anschließend, dass eine Liste von SubmitItem-Werten ohne den bytes-like-object TypeError akzeptiert wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Describe the bug
I have an API that accepts a JSON list inside form-data, so the request is expected to look like this:
input=[{...}, {...}]
However, when I pass the list to the generated client, the request fails with the following error.
Could you please take a look and let me know what might be going wrong here?
from openapi_client import ApiClient, Configuration, DefaultApi, SubmitPostRequestInput, SubmitItem
config = Configuration()
config.host = "https://api.example.com"
api_client = ApiClient(configuration=config)
api_instance = DefaultApi(api_client)
request_input = SubmitPostRequestInput(
[
SubmitItem(flag1=True, flag2=False),
SubmitItem(flag1=False, flag2=True)
]
)
api_instance.submit_post(input=request_input, inlcude_ses=True)
With the generated client and the code above I am getting the following error
File c:\Users\1592\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\_request_methods.py:264, in RequestMethods.request_encode_body(self, method, url, fields, headers, encode_multipart, multipart_boundary, **urlopen_kw)
259 raise TypeError(
260 "request got values for both 'fields' and 'body', can only specify one."
261 )
263 if encode_multipart:
--> [264](file:///C:/Users/1592/AppData/Local/Programs/Python/Python311/Lib/site-packages/urllib3/_request_methods.py:264) body, content_type = encode_multipart_formdata(
265 fields, boundary=multipart_boundary
266 )
267 else:
268 body, content_type = (
269 urlencode(fields), # type: ignore[arg-type]
270 "application/x-www-form-urlencoded",
271 )
File c:\Users\1592\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\filepost.py:[81](file:///C:/Users/1592/AppData/Local/Programs/Python/Python311/Lib/site-packages/urllib3/filepost.py:81), in encode_multipart_formdata(fields, boundary)
79 writer(body).write(data)
80 else:
---> 81 body.write(data)
83 body.write(b"\r\n")
85 body.write(f"--{boundary}--\r\n".encode("latin-1"))
TypeError: a bytes-like object is required, not 'list'
Please use the below spec file and above sample snippet to reproduce the issue
OpenAPI Spec File
openapi: 3.0.3
info:
title: Simple Form Data API
version: 1.0.0
paths:
/submit:
post:
summary: Submit form data with flags
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
input:
oneOf:
- $ref: '#/components/schemas/SubmitItem'
- type: array
items:
$ref: '#/components/schemas/SubmitItem'
inlcude_ses:
type: boolean
responses:
'200':
description: Successful submission
components:
schemas:
SubmitItem:
type: object
properties:
flag1:
type: boolean
flag2:
type: boolean
Desktop (please complete the following information):
- OS: windows
- Python Version: 3.11
- openapi-generator version - 7.20.0-SNAPSHOT (Docker)
- Vorherrschende Sprache
- Python
- Sterne
- 2k
- Forks
- 293
- Ø Merge
- 34 Min.
- Gemergte PRs (30 T.)
- 1
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus openapi-generators/openapi-python-client
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
openapi-generators/openapi-python-client#1451 · 1 Kommentar ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 52/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 64/100
openapi-generators/openapi-python-client#1435 · 1 Kommentar ·
Alle Issues in openapi-generators/openapi-python-client
Ähnliche Issues
-
essnmx good first issue
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 95/100
-
[Feature] 奇物选择添加优先级 Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
syfoud/Simulated_Scepter#174 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Giskard-AI/giskard-oss#2840 · 1 Kommentar ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Offenarea: repo bug perceived difficulty: 2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
yeti-platform/yeti#1380 ·