user2040597
user2040597

Reputation: 489

Python send data and jpg via http

I would like to send data to a server via http and include some parameters and a picture.

Has anyone managed to do this with Python?

I am using a Raspberry Pi so I have python 2.7.3.

Many thanks for your help,

John.

Upvotes: 1

Views: 1012

Answers (1)

Jason Sperske
Jason Sperske

Reputation: 30416

Here is an approach with the Requests lib (from doc):

>>> url = 'http://httpbin.org/post'
>>> files = {'file': open('report.xls', 'rb')}

>>> r = requests.post(url, files=files)
>>> r.text
{
  ...
  "files": {
    "file": "<censored...binary...data>"
  },
  ...
}

Upvotes: 1

Related Questions