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

Improve Login Flow #79

Merged
merged 3 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -632,10 +632,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 @@ -646,7 +646,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 @@ -779,14 +779,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)