From 6968cd6c69cc72e6b692c744fef47adfa7d28c6b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 28 Aug 2021 14:18:49 +0100 Subject: [PATCH] companion: Rename Auth.session to requests_session So as to not confuse with companion.session. --- Contributing.md | 4 ++-- companion.py | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Contributing.md b/Contributing.md index c74953a1..bdbf4634 100644 --- a/Contributing.md +++ b/Contributing.md @@ -247,10 +247,10 @@ from edmc_data import DEBUG_WEBSERVER_HOST, DEBUG_WEBSERVER_PORT TARGET_URL = 'https://www.edsm.net/api-journal-v1' if 'edsm' in debug_senders: - TARGET_URL = f'http://{DEBUG_WEBSERVER_HOST}:{DEBUG_WEBSERVER_PORT}/edsm' + TARGET_URL = f'http://{DEBUG_WEBSERVER_HOST}:{DEBUG_WEBSERVER_PORT}/edsm' ... - r = this.session.post(TARGET_URL, data=data, timeout=_TIMEOUT) +r = this.requests_session.post(TARGET_URL, data=data, timeout=_TIMEOUT) ``` Be sure to set a URL path in the `TARGET_URL` that denotes where the data diff --git a/companion.py b/companion.py index c2770ca0..bb5d3605 100644 --- a/companion.py +++ b/companion.py @@ -295,15 +295,15 @@ class Auth(object): def __init__(self, cmdr: str) -> None: self.cmdr: str = cmdr - self.session = requests.Session() - self.session.headers['User-Agent'] = USER_AGENT + self.requests_session = requests.Session() + self.requests_session.headers['User-Agent'] = USER_AGENT self.verifier: Union[bytes, None] = None self.state: Union[str, None] = None def __del__(self) -> None: """Ensure our Session is closed if we're being deleted.""" - if self.session: - self.session.close() + if self.requests_session: + self.requests_session.close() def refresh(self) -> Optional[str]: """ @@ -334,7 +334,7 @@ class Auth(object): logger.debug('Attempting refresh with Frontier...') try: - r = self.session.post( + r = self.requests_session.post( FRONTIER_AUTH_SERVER + self.FRONTIER_AUTH_PATH_TOKEN, data=data, timeout=auth_timeout @@ -422,7 +422,7 @@ class Auth(object): # requests_log.setLevel(logging.DEBUG) # requests_log.propagate = True - r = self.session.post( + r = self.requests_session.post( FRONTIER_AUTH_SERVER + self.FRONTIER_AUTH_PATH_TOKEN, data=request_data, timeout=auth_timeout @@ -430,7 +430,7 @@ class Auth(object): data_token = r.json() if r.status_code == requests.codes.ok: # Now we need to /decode the token to check the customer_id against FID - r = self.session.get( + r = self.requests_session.get( FRONTIER_AUTH_SERVER + self.FRONTIER_AUTH_PATH_DECODE, headers={ 'Authorization': f'Bearer {data_token.get("access_token", "")}',