Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get response data from a python post request [duplicate]

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]>
like image 920
Mheni Avatar asked Jun 13 '26 04:06

Mheni


1 Answers

How about getting the content of the response?

For example:

print(response.text)

Or if you expect a JSON:

print(response.json())
like image 129
baduker Avatar answered Jun 14 '26 21:06

baduker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!