Search code examples
formspostpython-3.xmultipart

Multipart form encoding file upload in Python 3


I was wondering if it was possible to post to a form with enctype='multipart/form-data' in Python 3. I looked around and could only find things for Python 2 (such as poster).


Solution

  • Use requests, it supports python 3.

    import requests
    
    response = requests.post('http://httpbin.org/post', files={'file': open('filename','rb')})
    print(response.content)