bohdan Spinners
bohdan Spinners

Reputation: 3

POST a Multipart-Encoded File python

I cannot get a useful response from a website when making a POST request.

import requests

data = {'image':  ("biloha.jpg", open("biloha.jpg", "rb"), 'image/jpeg')}
r = requests.post("http://basic.photofunia.com/categories/all_effects/worker-by-the-billboard/",
                      data=data)
print(r.url)

I get response: http://basic.photofunia.com/categories/all_effects/worker-by-the-billboard?e=resource_not_found

But I have to get something like this:

Server: "nginx"
Date: "Fri, 16]un 2017 12:39:12 GMT"
Content-Type: "text/html"
Transfer-Encoding: "chunked"
Connection: "close"
Pragma: "no—cache"
X-Powered-By: "PFEngine/13"
Cache-Control: "no—store"
Expires: "Mon, 01 Jan 1997 12:00:00 GMT"
Location: "/results/5943d170846d7843628b45c7"

Upvotes: 0

Views: 538

Answers (1)

Arpit Solanki
Arpit Solanki

Reputation: 9921

For sending the multipart form data you have to pass the files parameter so that files can get uploaded.

import requests
import sys

data = {'image':  ("biloha.jpg", open(sys.argv[1], "rb"), 'image/jpeg')}
r = requests.post("http://basic.photofunia.com/categories/all_effects/worker-by-the-billboard/",
                      files=data)
print(r.url)

Upvotes: 1

Related Questions