0

What is the -x option in curl and how to implement equivalent command in python using the requests library. I want the following command to be in python.

curl \
  -X DELETE \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/octocat/hello-world

2 Answers 2

1
import requests

headers = {'Accept': 'application/vnd.github.v3+json'}

response = requests.delete(url='https://api.github.com/repos/octocat/hello-world', headers=headers)

-X DELETE is the HTTP method you are using, here we use delete method from requests module

-H is to specify the request headers, here we achieve it with headers parameter

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

Comments

0

I believe this would be:

import requests

headers = {
    'Accept': 'application/vnd.github.v3+json',
}

response = requests.delete('https://api.github.com/repos/octocat/hello-world', headers=headers)

Another alternative would be to use PycURL, which provides the setopt option:

crl = pycurl.Curl()
crl.setopt(crl.URL, "<url here>")
crl.setopt(crl.CUSTOMREQUEST, "DELETE")

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.