0

What is the best way to convert the below curl post into python request using the requests module:

curl -X POST https://api.google.com/gmail --data-urlencode json='{"user": [{"message":"abc123", "subject":"helloworld"}]}'

I tried using python requests as below, but it didn't work:

payload = {"user": [{"message":"abc123", "subject":"helloworld"}]}
url = https://api.google.com/gmail
requests.post(url, data=json.dumps(payload),auth=(user, password))

Can anybody help.

1
  • 1
    What do you mean by "it didn't work"? And you should set the url variable to be a string, not just some url. Surround it with " Commented Oct 12, 2016 at 0:21

1 Answer 1

0

As the comment mentioned, you should put your url variable string in quotes "" first.

Otherwise, your question is not clear. What errors are being thrown and/or behavior is happening?

New cURL method in Python

Sign up to request clarification or add additional context in comments.

2 Comments

it says returned nothing in payload
Have you tried putting quotes? Check out the link above for a newer way to use cURL in Python.

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.