HTTPX -Bibliothek gegen Curl -ProgrammPython

Python-Programme
Anonymous
 HTTPX -Bibliothek gegen Curl -Programm

Post by Anonymous »

Ich versuche, die HTTPX -Bibliothek zu verwenden, um eine Datei über eine von der Website bereitgestellte API zu veröffentlichen. Die API fordert einige zusätzliche Header an.
Hier ist mein Pyhton -Skript: < /p>
#!/usr/bin/python3
import httpx

files = {'file': ('Test.pdf', open('Test.pdf', 'rb'), 'application/pdf')}

url='https://some.api.domain/Api/1/documents/mandant'
headers= {\
'accept': 'application/json',\
'APPLICATION-ID': '42fxxxxxxx',\
'USER-TOKEN': '167axxxxx',\
'Content-Type': 'multipart/form-data',\
}
data={\
'year': 2024,\
'month': 1,\
'folder': 3,\
'notify': False\
}

response = httpx.post(url, headers=headers, data=data, files=files)
print(response.status_code)

< /code>
Und hier ist der Curl -Befehlszeilenaufruf, um dasselbe zu tun: < /p>
curl -i -v -X 'POST' 'http://www.some.domain/' \
-H 'accept: application/json' \
-H 'APPLICATION-ID: 42xxxx' \
-H 'USER-TOKEN: 167axxxxx'\
-H 'Content-Type: multipart/form-data'\
-F 'year=2024'\
-F 'month=1'\
-F 'file=@Test.pdf;type=application/pdf'\
-F 'folder=3'\
-F 'notify=false'
< /code>
Ausführen des Python -Skripts Ich erhalte eine 412 -Antwort, was bedeutet, dass einige Parameter fehlen, unvollständig oder ungültig. Erhalten von 200 und die Datei wird übertragen. /P>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post