1

I'm trying to use Python3 with requests.post() but it doesn't return the expected payload, while using CURL (Bash) or Invoke-RestMethod (PwSh) I do get the Token for given account, but with the Python code below is like he's doing a GET instead the POST

request_headers = {'Content-Type': 'application/json'}
request_data = {"description": "AWX CLI Token"}
targeturl =(f"{awx_url}/api/v2/users/{user_id}/personal_tokens")
request = requests.post(targeturl, headers=request_headers, verify=False, data=request_data, auth=(awx_user,awx_pass ))

I've tried also different variations of the request.post() like using json=json.dumps(request_data).

There is no error, return 200.

Friedrich
  • 2,011
  • 2
  • 17
  • 19
Pepi0
  • 55
  • 7
  • So *what* does the endpoint return? can you post what is stored in `request.text` ? – Bijay Regmi May 04 '23 at 21:13
  • It does return the JSON of the content of /api/v2/users/.../personal_tokens, where all Tokens are masked - same as if I do a GET to that endpoint. Behave basically as if he's not doing a POST – Pepi0 May 05 '23 at 06:46
  • try changing `data=` parameter in `requests.post` to `json=` – Bijay Regmi May 05 '23 at 07:05
  • Tried, same result. There is 200 but I don't get what I should get in the post, is simply get the whole JSON with all values, not the new value that should be created by the POST. I also tried sending just the POST with no Data or additional values as they're not mandatory for such call – Pepi0 May 05 '23 at 10:57

0 Answers0