R Nanthak
R Nanthak

Reputation: 371

What is the python equivalent of curl -x

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

Upvotes: 0

Views: 1011

Answers (2)

michjnich
michjnich

Reputation: 3385

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")

Upvotes: 0

MukeshRKrish
MukeshRKrish

Reputation: 1090

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

Upvotes: 1

Related Questions