Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookies & parse_response issues with V1 #3

Open
JobeOneKenobi opened this issue Jul 14, 2024 · 10 comments
Open

Cookies & parse_response issues with V1 #3

JobeOneKenobi opened this issue Jul 14, 2024 · 10 comments

Comments

@JobeOneKenobi
Copy link

JobeOneKenobi commented Jul 14, 2024

V1 works the same using the v0 functionality, but when I try the new formatting for the get_flights, two issues:

  1. the cookies=Cookies.new() line, the Cookies reference is not working
  2. the parse_response function is breaking somehow, it's trynig to split a none value.

I'm testing it in an isolated environment with a simple main script, and installed it with pip only here is my test code

from fast_flights import FlightData, Passengers, create_filter, get_flights

Create a new filter

filter = create_filter(
flight_data=[
# Include more if it's not a one-way trip
FlightData(
date="2024-09-02", # Date of departure
from_airport="RSW",
to_airport="DCA"
),
# ... include more for round trips and multi-city trips
],
trip="one-way", # Trip (round-trip, one-way, multi-city)
seat="economy", # Seat (economy, premium-economy, business or first)
passengers=Passengers(
adults=1,
children=0,
infants_in_seat=0,
infants_on_lap=0
),
)

Get flights with a filter

result = get_flights(
filter,
dangerously_allow_looping_last_item=True,
cookies=Cookies.new().to_dict(),
currency="USD",
language="en"
)

The price is currently... low/typical/high

print("The price is currently", result.current_price)

Display the first flight

print(result.flights[0])

@AWeirdDev
Copy link
Owner

Hey there,

Could you please clarify what "Cookies reference is not working" mean? As for the broken parse_response() function, could you please provide an error log pointing where the error occurred or what type of error was it?

P.S. I was in a rush so I wasn't aware of my code being that broken, thanks for pointing this out. I'll look into the code tomorrow (if possible). Thanks!

Best

@JobeOneKenobi
Copy link
Author

Yes, I'll confess I'm a novice with Github, and by no means any expert coder.

For the cookies thing actually it looks like I just needed to add an import line:
image

@JobeOneKenobi
Copy link
Author

Ope, tack that back, when I do that it gives this error:
C:\Users\jobel\PycharmProjects\pythonProject\venv\Scripts\python.exe "C:\Users\jobel\PycharmProjects\pythonProject\Flight Helper\main.py"
Traceback (most recent call last):
File "C:\Users\jobel\PycharmProjects\pythonProject\Flight Helper\main.py", line 2, in
from fast_flights.cookies_impl import Cookies
File "C:\Users\jobel\PycharmProjects\pythonProject\venv\Lib\site-packages\fast_flights\cookies_impl.py", line 5, in
from .cookies_pb2 import Cookies as SOCS, Information, Datetime # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: cannot import name 'Cookies' from 'fast_flights.cookies_pb2' (C:\Users\jobel\PycharmProjects\pythonProject\venv\Lib\site-packages\fast_flights\cookies_pb2.py)

Process finished with exit code 1

@JobeOneKenobi
Copy link
Author

But anyways this is the error code for running it without the cookies line, that is the issue with parsing the response which seems to be the bigger problem (I haven't encountered any need for the cookies thing yet anyway):

Traceback (most recent call last):
File "C:\Users\jobel\PycharmProjects\pythonProject\Flight Helper\main.py", line 28, in
result = get_flights(
^^^^^^^^^^^^
File "C:\Users\jobel\PycharmProjects\pythonProject\venv\Lib\site-packages\fast_flights\core.py", line 119, in get_flights
results = parse_response(
^^^^^^^^^^^^^^^
File "C:\Users\jobel\PycharmProjects\pythonProject\venv\Lib\site-packages\fast_flights\core.py", line 70, in parse_response
departure_time = dp_ar_node[0].text(strip=True)
~~~~~~~~~~^^^
IndexError: list index out of range

Process finished with exit code 1

Now you mentioned a log file? I'm assuming you mean adding code that saves out errors like this to a log / txt file so that I don't have to copy past efrom the output screen? That is a good idea I should do that.

@AWeirdDev
Copy link
Owner

Hi there,

I've updated fast-flights to v1.2.

Cookies couldn't be imported because of the missing import in __init__.py. As for the IndexError, I assume it's because the departure time is not present sometimes.

pip install -U fast-flights

Let me know if I made other silly mistakes!

Best,
AWeirdDev

@JobeOneKenobi
Copy link
Author

Alright new, and even wierder, parse response error. Old ones seem to to be resolved
using same modified example code, updated to 1.2 and got the following error:

Traceback (most recent call last):
File "C:\Users\jobel\SynologyDrive\PycharmProjects\pythonProject\flights_package_test.py", line 28, in
result = get_flights(
^^^^^^^^^^^^
File "C:\Users\jobel\PycharmProjects\pythonProject\venv\Lib\site-packages\fast_flights\core.py", line 127, in get_flights
results = parse_response(
^^^^^^^^^^^^^^^
File "C:\Users\jobel\PycharmProjects\pythonProject\venv\Lib\site-packages\fast_flights\core.py", line 103, in parse_response
"stops": 0 if stops == "Nonstop" else int(stops.split(" ", 1)[0]),
^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''

Process finished with exit code 1

But here's what's wierd I went in and added some print statements to the nonstop parse / code and got this for this same code / result:

1 stop
['1', 'stop']
1 stop
['1', 'stop']
1 stop
['1', 'stop']
2 stops
['2', 'stops']
2 stops
['2', 'stops']
1 stop
['1', 'stop']
2 stops

So I have no clue how it's parsing / splitting out an empty string? '' Freaking wierd.

Here is my code just to be sure:

from fast_flights import FlightData, Passengers, create_filter, get_flights, Cookies

Create a new filter

filter1 = create_filter(
flight_data=[
# Include more if it's not a one-way trip
FlightData(
date="2024-08-21", # Date of departure
from_airport="IAD",
to_airport="JFK"
),
# ... include more for round trips and multi-city trips
],
trip="one-way", # Trip (round-trip, one-way, multi-city)
seat="economy", # Seat (economy, premium-economy, business or first)
passengers=Passengers(
adults=1,
children=0,
infants_in_seat=0,
infants_on_lap=0
),
)

Get flights with a filter

result = get_flights(
filter1,
dangerously_allow_looping_last_item=True,
cookies=Cookies.new().to_dict(),
currency="USD",
language="en"
)

The price is currently... low/typical/high

print("The price is currently", result.current_price)

Display the first flight

print(result.flights[1])

@JobeOneKenobi
Copy link
Author

Tried a few different dates and airports

AWeirdDev added a commit that referenced this issue Jul 29, 2024
Copy link

dosubot bot commented Oct 31, 2024

Hi, @JobeOneKenobi. I'm helping the flights team manage their backlog and am marking this issue as stale.

You've raised concerns about two main problems with the V1 functionality: the Cookies.new() line not working and an IndexError occurring in the parse_response function. AWeirdDev suggested updating to version 1.2, which resolved some errors but introduced a new ValueError related to parsing stops. I see that you're actively testing different scenarios and providing detailed error logs to assist in troubleshooting.

Could you please let the flights team know if this issue is still relevant to the latest version of the repository? If it is, a comment from you would be appreciated. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!

@dosubot dosubot bot added the stale Stale. label Oct 31, 2024
@JobeOneKenobi
Copy link
Author

JobeOneKenobi commented Oct 31, 2024 via email

@dosubot dosubot bot removed the stale Stale. label Oct 31, 2024
Copy link

dosubot bot commented Oct 31, 2024

@AWeirdDev, the user JobeOneKenobi has indicated that they paused testing but can take a look at the issue this weekend, suggesting they may have found a fix. Could you please assist them with the concerns regarding the V1 functionality? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants