mirror of
https://github.com/atoy3731/adguard-sync.git
synced 2024-09-20 15:06:02 +08:00
Merge pull request #2 from atoy3731/token-exception-handling
Add logging and exception handling for invalid token responses
This commit is contained in:
commit
85d35e9313
12
src/app.py
12
src/app.py
|
@ -35,6 +35,12 @@ def get_login_cookie(url, user, passwd):
|
|||
}
|
||||
|
||||
response = requests.post('{}/control/login'.format(url), data=json.dumps(creds))
|
||||
|
||||
if response.status_code != 200:
|
||||
print('ERROR: Unable to acquire cookie.')
|
||||
print('Message: {}'.format(response.text))
|
||||
return None
|
||||
|
||||
return response.cookies['agh_session']
|
||||
|
||||
|
||||
|
@ -128,6 +134,9 @@ if __name__ == '__main__':
|
|||
primary_cookie = get_login_cookie(ADGUARD_PRIMARY, ADGUARD_USER, ADGUARD_PASS)
|
||||
secondary_cookie = get_login_cookie(ADGUARD_SECONDARY, SECONDARY_ADGUARD_USER, SECONDARY_ADGUARD_PASS)
|
||||
|
||||
if primary_cookie is None or secondary_cookie is None:
|
||||
exit(1)
|
||||
|
||||
while True:
|
||||
try:
|
||||
primary_entries = get_entries(ADGUARD_PRIMARY, primary_cookie)
|
||||
|
@ -165,4 +174,7 @@ if __name__ == '__main__':
|
|||
primary_cookie = get_login_cookie(ADGUARD_PRIMARY, ADGUARD_USER, ADGUARD_PASS)
|
||||
secondary_cookie = get_login_cookie(ADGUARD_SECONDARY, SECONDARY_ADGUARD_USER, SECONDARY_ADGUARD_PASS)
|
||||
|
||||
if primary_cookie is None or secondary_cookie is None:
|
||||
exit(1)
|
||||
|
||||
time.sleep(REFRESH_INTERVAL_SECS)
|
||||
|
|
Loading…
Reference in a new issue