A RESTful way to upload an image would be to use a PUT request if you know the image URL is:
#!/usr/bin/env python3 import http.client h = http.client.HTTPConnection('example.com') h.request('PUT', '/file/pic.jpg', open('pic.jpg', 'rb')) print(h.getresponse().read())
upload_docs.py contains an example of uploading a file as multipart/form-data using basic HTTP authentication. It supports both Python 2.x and Python 3.
You can also use requests to send files as multipart/form-data :
#!/usr/bin/env python3 import requests response = requests.post('http://httpbin.org/post', files={'file': open('filename','rb')}) print(response.content)
source share