-1

I'm trying to access AWX API from a script Python.
The documentation has the ressource /api/v1/authtoken/ for that, however when visiting the URL: https://myHost/api/v1/authtoken/ It says that it can't find the ressource.

I also tried:

response = requests.get('https://myHost/api/login/', verify=False,
    data = json.dumps({"username": "user","password": "pass"}))
results = json.loads(response.text)
token = results['token']

But I get a :

ValueError: No JSON object could be decoded

AWX version: 10.0.0

Doc
  • 133
  • 1
  • 1
  • 10
  • 1
    Well, have you printed out `response.text` to see what's in there? Did you call [`response.raise_for_status`](https://requests.readthedocs.io/en/v3.0.0/api/#requests.Response.raise_for_status) like a good developer? Did you even briefly consider including the **version** of AWX you are using? Please do read the [how to ask](https://stackoverflow.com/help/how-to-ask) page – mdaniel Apr 21 '20 at 15:57

1 Answers1

1

The fine manual says that:

A GET to /api/login/ displays the login page of API browser

So = requests.get( is for sure not what you want; however, even if you were to switch to requests.post the very next line says:

It should be noted that the POST body of /api/login/ is not in JSON, but in HTTP form format. Four items should be provided in the form:

so data = json.dumps({ is also for sure also not what you want

mdaniel
  • 31,240
  • 5
  • 55
  • 58