I'm considering using the Python Requests library to post mp3s to an api, but all the examples of posting files in the documentation are for text files. Is it possible to use this library for audio?
Yes, it is possible to send any sequence of bytes with the library:
with open(audiofile, 'rb') as fobj:
    requests.post(url, files={'fieldname': fobj})
In fact, the first multipart-encoded file example in the requests documentation posts a binary file:
>>> url = 'http://httpbin.org/post'
>>> files = {'file': open('report.xls', 'rb')}
>>> r = requests.post(url, files=files)
>>> r.text
{
  ...
  "files": {
    "file": "<censored...binary...data>"
  },
  ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With