Attempt to fix Irish Times login

This commit is contained in:
Kovid Goyal 2021-12-23 11:01:49 +05:30
parent 1ce8a59eea
commit e0dfaaa389
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -51,26 +51,37 @@ class IrishTimes(BasicNewsRecipe):
# To understand the signin logic read signin javascript from submit button from # To understand the signin logic read signin javascript from submit button from
# https://www.irishtimes.com/signin # https://www.irishtimes.com/signin
br = BasicNewsRecipe.get_browser(self, user_agent='curl/7.80.0')
ip_data = json.loads(br.open('https://ipapi.co//json').read())
br = BasicNewsRecipe.get_browser(self) br = BasicNewsRecipe.get_browser(self)
url = 'https://www.irishtimes.com/signin' url = 'https://www.irishtimes.com/signin'
deviceid = str(uuid4()).replace('-', '') deviceid = str(uuid4()).replace('-', '')
# Enable debug stuff? # Enable debug stuff?
# br.set_debug_http(True) # br.set_debug_http(True)
br.open(url).read() br.open(url).read()
from pprint import pprint
pprint(ip_data)
br.set_cookie('IT_country', ip_data['country_code'], '.irishtimes.com')
br.set_cookie('IT_eu', 'true' if ip_data['in_eu'] else 'false', '.irishtimes.com')
rurl = 'https://www.irishtimes.com/auth-rest-api/v1/paywall/login' rurl = 'https://www.irishtimes.com/auth-rest-api/v1/paywall/login'
rq = Request(rurl, headers={ rq = Request(rurl, headers={
'Accept': '*/*', 'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.5', 'Accept-Language': 'en-US,en;q=0.5',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'https://www.irishtimes.com',
'Referer': url, 'Referer': url,
'X-Requested-With': 'XMLHttpRequest', 'X-Requested-With': 'XMLHttpRequest',
}, data=urlencode({'username': self.username, 'password': self.password,'deviceid':deviceid, 'persistent':'on'})) 'sec-fetch-site': 'same-origin',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
}, data=urlencode({'username': self.username, 'password': self.password, 'deviceid':deviceid, 'persistent':'on', 'rid': ''}))
r = br.open(rq) r = br.open(rq)
raw = r.read() raw = r.read()
data = json.loads(raw) data = json.loads(raw)
# print(data) # print(data)
if r.code != 200 or b'user_id' not in raw: if r.code != 200 or b'user_id' not in raw:
pprint(data)
raise ValueError('Failed to log in check username/password') raise ValueError('Failed to log in check username/password')
# Set cookie # Set cookie