0

I have an openapi3 server running that I'm trying to authenticate with.

I can do it with curl with no problems

curl -k -X POST "https://localhost:8787/api/login/user" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{\"username\":\"admin\",\"password\":\"admin\"}"

#and i get the token back
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwicm9sZSI6ImFkbWluIiwiaWF0IjoxNjEyODY3NDU3LCJleHAiOjE2MTI4NzEwNTd9.9eFgomcpJbinN7L4X1VOHfZGvJeUvHiv6WPjslba1To

but when using python I only get the response code (200) with no data including the token

here is my python script

import requests
import os

url = str(os.environ.get('API_SERVER_URL'))+'login/user'
head = {'accept': 'application/json', 'Content-Type': 'application/json'}
data = {"username": "admin", "password": "admin"}             }
response = requests.post(url, json=data, headers=head, verify=False)

print(response)

All I get with this is a 200 response

<Response [200]>
Helen
  • 58,317
  • 8
  • 161
  • 218
Mheni
  • 178
  • 1
  • 12
  • Does this answer your question? [How to extract HTTP response body from a Python requests call?](https://stackoverflow.com/questions/9029287/how-to-extract-http-response-body-from-a-python-requests-call), [How do I read a response from Python Requests?](https://stackoverflow.com/q/18810777/113116), [What's the best way to parse a JSON response from the requests library?](https://stackoverflow.com/q/16877422/113116), [HTTP requests and JSON parsing in Python](https://stackoverflow.com/q/6386308/113116) – Helen Feb 09 '21 at 10:58

1 Answers1

1

How about getting the content of the response?

For example:

print(response.text)

Or if you expect a JSON:

print(response.json())
baduker
  • 12,203
  • 9
  • 22
  • 39