0

PS - No I am not going to use python requests, cause it does not help creating readable streams of the file.

curl -i -H "Authorization":"eyJhbGciOiJIUzI1NiIsImV4cCI6MTQyNjcwNTY4NiwiaWF0IjoxNDI2NzAyMDg2fQ.eyJpZCI6MTc3fQ.yBwLFez2RnxTojLniL8YLItWVvBb90HF_yfhcsyg3lY" \
    -F user_data='{"user data": {"preferred_city":"Newyork","within_radious":"5"}}' \
    -F uploaded_documents=@mydocument.pdf \
    http://127.0.0.1:5000/api/city

I am trying to send both file and a json data in pycurl post method.
I am succesful in sending file alone only.
I found above example to send file and data in same api but not able to convert it to pycurl systax properly.
Can anyone please convert it to pycurl type code work?

Moon
  • 4,014
  • 3
  • 30
  • 66
Chidananda Nayak
  • 1,161
  • 1
  • 13
  • 45

2 Answers2

0

This will work for you

import pycurl
c = pycurl.Curl()      
c.setopt(pycurl.URL, "http://127.0.0.1:5000/api/city")
c.setopt(c.POST, 1)
c.setopt(pycurl.HTTPHEADER, ['Authorization: "eyJhbGciOiJIUzI1NiIsImV4cCI6MTQyNjcwNTY4NiwiaWF0IjoxNDI2NzAyMDg2fQ.eyJpZCI6MTc3fQ.yBwLFez2RnxTojLniL8YLItWVvBb90HF_yfhcsyg3lY"'])
data = json.dumps({"user data": {"preferred_city":"Newyork","within_radious":"5"}})
c.setopt(pycurl.POSTFIELDS,data)
c.setopt(c.HTTPPOST, [("uploaded_documents", (c.FORM_FILE, "mydocument.pdf"))])
c.perform()
c.close()
Nishant Patel
  • 1,334
  • 14
  • 22
0

You can try this package - http_pycurl.

The API it exposes is similar to the requests.

How to install

pip install http_pycurl

Specific usage is here.

luoyeqi
  • 31
  • 1