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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -