examples/multiparttest.py

18 lines
485 B
Python
Raw Normal View History

2020-03-25 04:03:16 +01:00
#!/usr/bin/env python3
import requests
import os.path
import json
FILE = '/home/marcsello/CommonStarling_102761_45.wav'
2020-03-25 04:06:41 +01:00
TAG = 'test'
2020-03-25 04:03:16 +01:00
2020-03-25 04:06:41 +01:00
# Files structure: (filename, data, content_type, headers)
2020-03-25 04:03:16 +01:00
files = {
2020-03-25 04:06:41 +01:00
"soundFile": (os.path.basename(FILE), open(FILE,'rb').read(), 'audio/wave', {'Content-length' : os.path.getsize(FILE)}),
"description" : (None, json.dumps({'tag' : TAG}), "application/json")
2020-03-25 04:03:16 +01:00
}
2020-03-25 04:06:41 +01:00
r = requests.post('http://localhost:5000/object', files=files)
2020-03-25 04:03:16 +01:00
r.raise_for_status()