### Handle AccessTokenInvalid Exception Source: https://github.com/jasondilworth56/iracingdataapi/blob/main/README.md Example of how to catch an AccessTokenInvalid exception and reinitialize the client with a new token. Token refreshing logic must be implemented externally. ```python try: lap_data = idc.result_lap_data(subsession_id=12345678, cust_id=987654) except AccessTokenInvalid: # access token is invalid new_token = do_something_in_your_code_to_refresh_token() idc = irDataClient(access_token=[NEW TOKEN]) lap_data = idc.result_lap_data(subsession_id=12345678, cust_id=987654) ``` -------------------------------- ### Initialize irDataClient with Username and Password Source: https://github.com/jasondilworth56/iracingdataapi/blob/main/README.md Instantiate the irDataClient using iRacing username and password for authentication. This method is used when OAuth2 is not available or preferred. ```python from iracingdataapi.client import irDataClient idc = irDataClient(username=[YOUR iRACING USERNAME], password=[YOUR iRACING PASSWORD]) ``` -------------------------------- ### Initialize irDataClient with OAuth2 Token Source: https://github.com/jasondilworth56/iracingdataapi/blob/main/README.md Instantiate the irDataClient using an OAuth2 access token. Ensure the token is valid. The client will raise an AccessTokenInvalid exception if the token expires. ```python from iracingdataapi.client import irDataClient idc = irDataClient(access_token=[YOUR OAUTH2 TOKEN]) ``` -------------------------------- ### Initialize irDataClient with Pydantic Type Hinting Source: https://github.com/jasondilworth56/iracingdataapi/blob/main/README.md Enable Pydantic model objects for method return types by setting use_pydantic to True during client initialization. ```python idc = irDataClient(access_token=[YOUR OAUTH2 TOKEN], use_pydantic=True) ``` -------------------------------- ### Access and Interpret Rate Limit Information Source: https://github.com/jasondilworth56/iracingdataapi/blob/main/README.md After making an API call, access the rate_limit property to check the status of API rate limits. This includes limit, remaining requests, and reset time. ```python from iracingdataapi.client import irDataClient idc = irDataClient(username=[YOUR iRACING USERNAME], password=[YOUR iRACING PASSWORD]) # Make an API call idc.get_cars() # Check rate limit information if idc.rate_limit.has_data: print(f"Rate limit: {idc.rate_limit.limit}") print(f"Remaining requests: {idc.rate_limit.remaining}") print(f"Reset time (UTC): {idc.rate_limit.reset_time}") print(f"Seconds until reset: {idc.rate_limit.seconds_until_reset}") # Check if we're rate limited if idc.rate_limit.is_rate_limited: print("Rate limit exceeded! Wait before making more requests.") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.