1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-17 17:42:20 +03:00

Hande companion API session timing out more gracefully.

This commit is contained in:
Jonathan Harris 2015-07-26 17:33:05 +01:00
parent 47a00fbf0a
commit 5ff1c843b8

View File

@ -21,6 +21,10 @@ from config import config
holdoff = 120 # be nice holdoff = 120 # be nice
timeout = 10 # requests timeout timeout = 10 # requests timeout
URL_LOGIN = 'https://companion.orerve.net/user/login'
URL_CONFIRM = 'https://companion.orerve.net/user/confirm'
URL_QUERY = 'https://companion.orerve.net/profile'
# Map values reported by the Companion interface to names displayed in-game and recognized by trade tools # Map values reported by the Companion interface to names displayed in-game and recognized by trade tools
@ -137,7 +141,7 @@ class Session:
else: else:
self.credentials = { 'email' : username, 'password' : password } self.credentials = { 'email' : username, 'password' : password }
try: try:
r = self.session.post('https://companion.orerve.net/user/login', data = self.credentials, timeout=timeout) r = self.session.post(URL_LOGIN, data = self.credentials, timeout=timeout)
except: except:
if __debug__: print_exc() if __debug__: print_exc()
raise ServerError() raise ServerError()
@ -160,7 +164,7 @@ class Session:
return r.status_code return r.status_code
def verify(self, code): def verify(self, code):
r = self.session.post('https://companion.orerve.net/user/confirm', data = {'code' : code}, timeout=timeout) r = self.session.post(URL_CONFIRM, data = {'code' : code}, timeout=timeout)
r.raise_for_status() r.raise_for_status()
# verification doesn't actually return a yes/no, so log in again to determine state # verification doesn't actually return a yes/no, so log in again to determine state
try: try:
@ -176,17 +180,17 @@ class Session:
elif self.state == Session.STATE_AUTH: elif self.state == Session.STATE_AUTH:
raise VerificationRequired() raise VerificationRequired()
try: try:
r = self.session.get('https://companion.orerve.net/profile', timeout=timeout) r = self.session.get(URL_QUERY, timeout=timeout)
except: except:
if __debug__: print_exc() if __debug__: print_exc()
raise ServerError() raise ServerError()
if r.status_code != requests.codes.ok: if r.status_code != requests.codes.ok:
self.dump(r) self.dump(r)
if r.status_code == requests.codes.forbidden: if r.status_code == requests.codes.forbidden or (r.history and r.url == URL_LOGIN):
# Start again - maybe our session cookie expired? # Start again - maybe our session cookie expired?
self.login() self.login()
self.query() return self.query()
r.raise_for_status() r.raise_for_status()
try: try: