Skip to content

Commit

Permalink
Merge pull request #79 from Esterni/xriga/use-custom-auth-error
Browse files Browse the repository at this point in the history
Improve Login Flow
  • Loading branch information
Esterni authored Feb 17, 2021
2 parents b09f98b + 596cfb6 commit 5305895
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
46 changes: 23 additions & 23 deletions pyracing/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
session_data,
upcoming_events,
)
from .exceptions.authentication_error import AuthenticationError

from datetime import datetime
import httpx
Expand Down Expand Up @@ -53,16 +54,15 @@ async def _authenticate(self):
'todaysdate': '' # Unknown purpose, but exists as a hidden form.
}

auth_post = await self.session.post(ct.URL_LOGIN2, data=login_data)
auth_response = await self.session.post(ct.URL_LOGIN2, data=login_data)

if 'failedlogin' in str(auth_post.url):
logger.warning('Login Failed. Please check credentials')
raise UserWarning(
if 'failedlogin' in str(auth_response.url):
logger.warning(
'The login POST request was redirected to /failedlogin, '
'indicating an authentication failure. If credentials are '
'correct, check that a captcha is not required by manually '
'visiting members.iracing.com'
)
'visiting members.iracing.com')
raise AuthenticationError('Login Failed', auth_response)
else:
logger.info('Login successful')

Expand Down Expand Up @@ -96,10 +96,10 @@ async def _build_request(self, url, params):
return response

async def active_op_counts(
self,
count_max=250,
include_empty='n',
cust_id=None
self,
count_max=250,
include_empty='n',
cust_id=None
):
""" Returns session information for all 'open practice' sessions that
are currently active. By default this only includes sessions with
Expand Down Expand Up @@ -635,10 +635,10 @@ async def race_guide(
x in response.json()['series']]

async def race_laps_all(
self,
subsession_id,
car_class_id=None,
sim_session_type=ct.SimSessionType.race.value
self,
subsession_id,
car_class_id=None,
sim_session_type=ct.SimSessionType.race.value
):
""" Returns information about all laps of a race for *every*
driver. The class of car can be set for multiclass races.
Expand All @@ -649,7 +649,7 @@ async def race_laps_all(
'subsessionid': subsession_id,
'carclassid': car_class_id,
'simsesnum': sim_session_type
}
}
url = ct.URL_LAPS_ALL
response = await self._build_request(url, payload)

Expand Down Expand Up @@ -782,14 +782,14 @@ async def total_registered_all(self):
return [upcoming_events.TotalRegistered(x) for x in response.json()]

async def world_records(
self,
year,
quarter,
car_id,
track_id,
result_num_low=1,
result_num_high=25,
cust_id=None
self,
year,
quarter,
car_id,
track_id,
result_num_low=1,
result_num_high=25,
cust_id=None
):
""" Returns laptimes with the requested paramaters. Filters can also
be seen on the /worldrecords.jsp page on the membersite.
Expand Down
Empty file added pyracing/exceptions/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions pyracing/exceptions/authentication_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AuthenticationError(Exception):
"""Raised when our attempt to authenticate fails"""
def __init__(self, message, response):
self.response = response
super(AuthenticationError, self).__init__(message)

0 comments on commit 5305895

Please sign in to comment.