I'm new to python & getting stuck in this... My code does some simple stuff, it requests an API endpoint and fetches the user name from the response, and makes a table as input we take mobile number .after a successful search it will give us the option to search again. the problem I faced when the invalid mobile number was given as input the code exit, the invalid response content-length is 160 so we can easily figure out the invalid request by the content-length, so i store the response content-length in z3 varibale . is there any way to check if the content-length is equal to 160 it will print data not found and give us chance to search again. if content-length is less than 160 it will fetch the data which I have written in my code
Here is the code :
from rich.console import Console
from rich.table import Table
from rich import print
import requests
p = True
while p == True:
num = input ("Enter the mobile number :")
x = num
data = {'account_type': '11' ,'account_no': x }
cookies = {'token': '121212ad2122sdsd2323asas12312'}
response = requests.post('https://pytest.com/api/user/get_user_info/', data , cookies=cookies)
z1 = response.json()
z2 = response.headers
z3 = z2["Content-Length"]
z4 = z1["data"]
z5 = z4["acc_title"]
table = Table(title="[+] Found [+]", style="bold")
table.add_column("Name", justify="right", style="cyan", no_wrap=True)
table.add_row( z5 )
console = Console()
console.print(table)
answer = input("want to search again? ")
if answer == "yes":
continue
else:
exit()
Need your help Thanks
Aucun commentaire:
Enregistrer un commentaire