I want to login by web API. The flowing code is working properly if I use curl at command line and I get a TOKEN.
LOGIN_RESULT=$(curl "$URL/application/login" --data-binary '{"login":"user","password":"password"}' )
# extract the token from the server's reponse
# (Requires the json parser "jq" , sudo apt install jq)
TOKEN=$(jq .token <<< $LOGIN_RESULT |tr -d '"')
I would like to write a Python script which do same action, but I received always error.
I need a TOKEN but I always run a error.
Python:
payload = {'login':'spn','password':'password'}
response = requests.post('http://...login/', data=payload)
print(response)
print(response.status_code)
print(response.text)
<Response [401]> 401 {"message": "Restricted area, token is not valid.", "code": "ERROR_LOGIN", "parameters": ""}