Convert this curl -F cmdline to python with request

Viewed 44

I try to do this:

curl -X POST -F file=@'infile.jpg' --output outfile.jpg 'http://pury.fi/censor?type=pixel&classes=ftite,fgene,fgenc'

form this site: https://pury.fi/site/api

in python to automate it as program and give it a UI.

Now ... There is the problem. How can I do this request in python? I tried it like this:

    import requests

params = (
    ('type', 'pixel'),
    ('classes', 'ftite,fgene,fgenc'),
)

files = {
    'file': open('infile.jpg', 'rb'),
}

response = requests.post('http://pury.fi/censor', params=params, files=files)

with open('outfile.jpg', 'wb') as f:
    f.write(response.content)

and got a corrupted file. So can someone please help me?

0 Answers
Related