Nov-04-2023, 05:43 AM
(This post was last modified: Nov-04-2023, 05:43 AM by deanhystad.)
Quote:ent from the output_found_flights gets returned as emptyReally? output_from_flights either returns a dictionary or it returns None. None is not the same as empty. {} is empty.
When you run your code, do you see the message box asking if it is ok to open the web browser? If you don't see that, do you see this error messge?
messagebox.showerror(title="Ooops",message="No flights were found")I think it likely the query returns nothing and your code raises a key error when it tries to use flights['data']. Even if the request was successful I think there are several errors in the function that will raise exceptions. Verify that the request is made at all.
This makes no sense:
try: lowest_price = round(float(ent["lowest_price"]), 2) except ValueError: messagebox.showerror(title="Ooops", message="You have not entered appropriate input for the lowest price variable")Popping up a message window is not handling the error. Immediately after this code you send your request and process the response even though you haven't assigned a value to lowest_price. This will result in the code raising a NameError when you try to use lowest_price in the function.
Python is not C, use iterators instead of indexing. Instead of this:
for i in range(0, len(flights['data'])): flight_price = round(float(flights['data'][0]['price']), 2) # <- Notice the index error. Should be ['data'][i] if flight_price <= lowest_price:Do this:
for flight in flights["data"]: if flight["price"] <= lowest_price:Looking at your code I think you are trying to do too much at once. Break up the program into smaller parts an solve them individually. For example, write a program that only does the request part. What happens if you make an invalid request? How do can you identify and correct the problem. How do you filter the responses? Currently you look for a price lower than your entered price. This might ignore lower prices. Once you are happy with how the request and filtering work you can fold it back into your program.