Skip to content
Advertisement

create request with python requests (translation from another language to python)

curl -v POST https://api-m.sandbox.paypal.com/v1/oauth2/token 
  -H "Accept: application/json" 
  -H "Accept-Language: en_US" 
  -u "CLIENT_ID:SECRET" 
  -d "grant_type=client_credentials"

This piece of code is from the api documentation. I can’t figure out how to perform this action in python. Please help me to complete this query using python.

Advertisement

Answer

A simple translation:

resp = requests.post(
    url="https://api-m.sandbox.paypal.com/v1/oauth2/token",
    auth=("CLIENT_ID", "SECRET"),
    data=b"grant_type=client_credentials",
    headers={
        "Accept": "application/json",
        "Accept-Language": "en_US",
    },
)
resp.raise_for_status()
print(resp.json())
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement