1
I made a Python URL to check some information of my client, everything is going well, the answer of my api is json, I would like to know how I do for if the api has, for example "userid", it samples a "OK" in the console.
import requests
url = "https://minhaapi.com/v1/login/username"
querystring = {"countryCode":"BR"}
payload = "username=user&password=teste123&clientVersion=2.4.9-undefined"
headers = {
'Content-Type': "application/x-www-form-urlencoded",
'x-requested-with': "XMLHttpRequest",
'x-tidal-token': "wdgaB1CilGA-S_s2"
}
response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
print(response.text)
Resposta da minha API(Quando o usuário loga com as informações no curl):
{"userId":57261722,"sessionId":"5b1ada5b-addf-4804-a55e-a12f36959ff1","countryCode":"BR"}
I tried this code, but I couldn’t:
for url in response.text:
if 'userId' in url.lower():
print ("OK")
I just want you to print on the "OK" screen when Curl displays the json response above (that’s when the user logs in), and if a different message appears it prints "Error" on the screen
json, friend....
– user113606
Please undo your edit and return the question to its original form. The original question is totally different and the accepted answer reflects this. It is important to leave questions in their original forms because other people with similar doubts can reach them through searches. It’s okay to create a new question to ask a different question.
– Pedro von Hertwig Batista
Ready friend, could you try to help me in the other question ? Thank you
– user113606