0

I'm trying to send a picture to a server I've made, now the problem is that the following curl code from terminal:

curl -X POST -F 'file=@path' -F 'delete_image=yes' url

where path is the absolute path of the image and url is url of the server

The problem is this code (that should be the exact tranlation in python is not working and it's returning an error 400 "bad request"

files = [
     ('file', open('/Users/viewermac_1/Desktop/Testbed_Web/test.png','rb')),
     ('delete_image', 'yes'),
]

test = requests.post(url, files=files)

Update: Putting delete_image as data works, but I'm not receiving anything back from the server (I'm supposed to receive a link)

4
  • 1
    ('delete_image', 'yes') isn't a file. Maybe you should pass that part to data. Commented Jun 25, 2017 at 8:35
  • 1
    pass delete_image to data Commented Jun 25, 2017 at 8:38
  • Possible duplicate of Uploading files using requests and send extra data Commented Jun 25, 2017 at 8:39
  • but the terminal code works even if the delete_image is a -F Commented Jun 25, 2017 at 8:42

1 Answer 1

0

Try using this code :

import requests

files = {
    'file': ('path', open('/Users/viewermac_1/Desktop/Testbed_Web/test.png', 'rb')),
    'delete_image': (None, 'yes'),
}

response = requests.post(url, files=files)
Sign up to request clarification or add additional context in comments.

Comments

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.