Response status code 400 when using python module Requests with Sitescout API

10,148

It has been resolved. I did not put grant_type=client_credentials which, when added, returns a 200.

The docs say "Optionally, you can add form parameter scope to indicate which scopes you are requesting access to; the scope values must be space delimited (e.g., STATS AUDIENCES)." But it is the "&scope=STATS" param that is optional, not all params. The example confused me.

Now my code reads

...

params = {  "grant_type" : "client_credentials" }

response = requests.post(url, headers=headers, params=params)

...

which works.

Share:
10,148
Iluvatar14
Author by

Iluvatar14

Updated on August 01, 2022

Comments

  • Iluvatar14
    Iluvatar14 over 1 year

    I have a client id and client secret and am attempting to generate an auth token by following Sitescout's api docs. I'm using python module Requests and am getting a 400 status code back, aka malformed request, but I can't seem to figure out why.

    My code:

    import requests
    
    url = "https://api.sitescout.com/oauth/token"
    headers = { 
                "Host": "api.sitescout.com",
                "Authorization": "Basic YmVldGhvdmVuOmxldG1laW4=",
                "Content-Type": "application/x-www-form-urlencoded",
                "Accept": "application/json",
                "Content-Length": "41"
            }
    
    # Do the HTTP request
    response = requests.post(url, headers=headers)
    
    response.status_code
    

    That is the fake base64 Authorization header provided in the docs so this snippet returns a 401 error, aka unauthorized (I have my own auth of course).

    Can anyone tell me what's wrong with this?