1

I'm trying to convert the cURL command to python requests, but hitting a wall. Maybe someone will have an idea.

I was using this site for reference and I have such a cURL command:

curl -F "[email protected]" -H "Authorization: ApiKey xxxxxxxxxxx" -F 'scan_type=Arachni Scan' -F 'tags=test' -F 'active=true' -F 'scan_date=2018-11-15' -F 'engagement=/api/v1/engagements/1/'  -F 'eid=1' https://example.com:443/api/v1/importscan/

After the conversion to python, my script extract looks like this:

files = {
    'file': ('myfile.json', open('myfile.json', 'rb')),
    'scan_type': 'Arachni Scan',
    'tags': 'test',
    'active': 'true',
    'scan_date': '2018-11-15',
    'engagement': '/api/v1/engagements/1/',
    'eid': '1',
}

response = requests.post('https://example.com:443/api/v1/importscan/', headers=headers, files=files)
print response.text

Unfortunately, the cURL command succeeds, but the python request returns

{"error": "Request is not valid JSON."}

What am I missing here? Thanks!

1
  • 1
    Have you tried: (1) using json.dumps(), (2) using a list instead of a tuple for 'file', or (3) doing open(...).read() instead of just open()? Commented Nov 15, 2018 at 16:02

1 Answer 1

1
import json

response = requests.post('https://example.com:443/api/v1/importscan/', headers=headers, files=json.dumps(files))

Use json.dumps would do the trick.

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.