0

My code is:

headers={"Content-type": "application/x-www-form-urlencoded","Accept": "multipart/form-data"}
cox = httplib.HTTPConnection("somedomain.com")
params=urllib.urlencode( {'par1':'1','par2':'2'})
cox.request("POST","/cportal/public/api/edit?par3=3&par4=4",params,headers)

along two POST parameters par1 and par2, I want to send a file. how can I do that?

3
  • 1
    first things first, i always use requests whenever possible. they make it more straight forward Commented May 10, 2018 at 17:05
  • Possible duplicate of Send file using POST from a Python script Commented May 10, 2018 at 17:08
  • Thanks Barmar, but this script sends only file, I want to POST file and parameters Commented May 10, 2018 at 17:11

1 Answer 1

1

using requests

import requests
site = 'site.com'
filename = 'image.jpg'

At The Place Of 'Image' , Add The ID Of The Upload File IN The Site:

file={'image':(filename, open(filename, 'r'),'multipart/from-data')}
data = {
      "Button" : "Submit" # Button ID on html
}
r = requests.post(site, files=file, data=data)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, I will check

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.