Python requests equivalent of following curl code -


could please inform python requests equivalent of following curl code upload file knack? part after -f option. thank you

curl -x post "https://api.knack.com/v1/applications/your-app-id/assets/file/upload" \   -h 'content-type: multipart/form-data' \   -h 'x-knack-rest-api-key: your-api-key' \   -f "files=@/path/to/your/file.txt" 

use requests.post files , headers. curl code equivalent to:

url = "https://api.knack.com/v1/applications/your-app-id/assets/file/upload" files = {'files':open('/path/to/your/file.txt', 'rb')} headers = {'x-knack-rest-api-key': 'your-api-key'} r = requests.post(url, headers=headers, files=files) 

when using files argument, requests creates necessary headers automatically don't need have "content-type" or "content-length" in headers.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -