I am trying to upload a file to Podio using file upload POST operation ( "https://api.podio.com/file/" ) using Python 3.7. Please find below the details about the code.
# File Upload
fin = open(input_path, 'rb')
files = {'source': ('report.txt', fin, 'text/plain')}
uploadResponse = requests.post(PODIO_BASE_URL + "file/", files=files,
headers=bearerHeader)
I did make sure that i followed the contracts mentioned in Podio API documentation
- Using multipart/form-data as the content-type
- Specifying 'source' parameter with payload content as a byte array
- Specifying 'filename' parameter ( the first value in the tuple in the above mentioned code) .
I am getting the below error while doing this operation:-
File upload reponse: {'error_parameters': {}, 'error_detail': None, 'error_propagate': False, 'request': {'url': 'http://api.podio.com/file/', 'query_string': '', 'method': 'POST'}, 'error_description': 'Invalid value null (null): must be non empty string', 'error': 'invalid_value'}
Please find below the post request which i captured using the prepare method ( i have purposefully removed the bearer value from the below snippet ).
req.prepare()
<PreparedRequest [POST]>
special variables:
function variables:
body: b'--5e83f2bb93a03c8b128f6158c00863c4\r\nContent-Disposition: form-data; name="source"; filename="report.txt"\r\n\r\ntesting\r\n--5e83f2bb93a03c8b128f6158c00863c4--\r\n'
headers: {'Authorization': 'Bearer ', 'Content-Length': '155', 'Content-Type': 'multipart/form-data; boundary=5e83f2bb93a03c8b128f6158c00863c4'}
hooks: {'response': []}
method: 'POST'
path_url: '/file/'
url: 'https://api.podio.com/file/'
_body_position: None
_cookies: <RequestsCookieJar[]>
_encode_files: <function RequestEncodingMixin._encode_files at 0x0000018437560E18>
_encode_params: <function RequestEncodingMixin._encode_params at 0x0000018437560D90>
_get_idna_encoded_host: <function PreparedRequest._get_idna_encoded_host at 0x000001843756C488>
Any pointers on this would be highly appreciated. Thanks in advance for the help.