@@ -57,9 +57,25 @@ def __init__(
57
57
agency_id : str | None = None ,
58
58
) -> None :
59
59
self .agency_id : str | None = agency_id
60
- self .headers : dict [str , str ] = {
61
- "Accept" : "application/json, text/javascript, */*; q=0.01" ,
62
- }
60
+
61
+ self ._session : requests .Session = requests .Session ()
62
+ self ._session .headers .update (
63
+ {
64
+ "User-Agent" : "PyNextBus" ,
65
+ "Accept" : "application/json" ,
66
+ "Accept-Language" : "en-US,en;q=0.5" ,
67
+ "Accept-Encoding" : "gzip, deflate, br, zstd" ,
68
+ "Compress" : "true" ,
69
+ "DNT" : "1" ,
70
+ "Sec-Fetch-Dest" : "empty" ,
71
+ "Sec-Fetch-Mode" : "cors" ,
72
+ "Connection" : "keep-alive" ,
73
+ # Additional headers used in browser
74
+ # "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:138.0) Gecko/20100101 Firefox/138.0",
75
+ # "Referer": "https://rider.umoiq.com/",
76
+ # "Origin": "https://rider.umoiq.com",
77
+ }
78
+ )
63
79
64
80
self ._rate_limit : int = 0
65
81
self ._rate_limit_remaining : int = 0
@@ -169,7 +185,7 @@ def _get(
169
185
try :
170
186
url = f"{ self .base_url } /{ endpoint } "
171
187
LOG .debug ("GET %s" , url )
172
- response = requests . get (url , params = params , headers = self . headers )
188
+ response = self . _session . get (url , params = params )
173
189
response .raise_for_status ()
174
190
175
191
# Track rate limit information
@@ -183,6 +199,7 @@ def _get(
183
199
)
184
200
185
201
return response .json ()
202
+
186
203
except HTTPError as exc :
187
204
raise NextBusHTTPError ("Error from the NextBus API" , exc ) from exc
188
205
except json .decoder .JSONDecodeError as exc :
0 commit comments