HTTP POST binary files using Python: concise non-pycurl examples?

前端 未结 5 1208
-上瘾入骨i
-上瘾入骨i 2021-02-06 13:29

I\'m interested in writing a short python script which uploads a short binary file (.wav/.raw audio) via a POST request to a remote server.

I\'ve done this with pycurl,

5条回答
  •  一整个雨季
    2021-02-06 14:12

    How's urllib substantially more verbose? You build postdict basically the same way, except you start with

    postdict = [ ('userfile', open(wavfile, 'rb').read()) ]
    

    Once you vave postdict,

    resp = urllib.urlopen(url, urllib.urlencode(postdict))
    

    and then you get and save resp.read() and maybe unquote and try JSON-loading if needed. Seems like it would be actually shorter! So what am I missing...?

提交回复
热议问题