From 4eed591ea1489490ce9ed7548ecc5dc9ed4d9b40 Mon Sep 17 00:00:00 2001 From: David Christenson Date: Tue, 7 Mar 2017 13:17:39 -0700 Subject: [PATCH] Update hash endpoint, catch SocksError explicitly --- aiopogo/auth_ptc.py | 8 ++++++-- aiopogo/exceptions.py | 6 +----- aiopogo/hash_server.py | 2 +- aiopogo/rpc_api.py | 6 +++++- setup.py | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/aiopogo/auth_ptc.py b/aiopogo/auth_ptc.py index f3b636da..173f7f55 100755 --- a/aiopogo/auth_ptc.py +++ b/aiopogo/auth_ptc.py @@ -2,6 +2,10 @@ from asyncio import get_event_loop, TimeoutError, CancelledError from aiohttp import TCPConnector, ClientSession, ClientError, DisconnectedError, HttpProcessingError +try: + from aiosocks.errors import SocksError +except ImportError: + class SocksError(Exception): pass from .session import socks_connector, CONN_TIMEOUT from .auth import Auth @@ -110,7 +114,7 @@ async def user_login(self, username=None, password=None, retry=True): raise AuthConnectionException('Error {} during user_login: {}'.format(e.code, e.message)) except (TimeoutError, TimeoutException) as e: raise AuthTimeoutException('user_login timeout.') from e - except ProxyException as e: + except (ProxyException, SocksError) as e: raise ProxyException('Proxy connection error during user_login.') from e except jexc as e: raise AuthException('Unable to parse user_login response.') from e @@ -183,7 +187,7 @@ async def get_access_token(self, force_refresh=False): raise AuthConnectionException('Error {} while fetching access token: {}'.format(e.code, e.message)) except (TimeoutError, TimeoutException) as e: raise AuthTimeoutException('Access token request timed out.') from e - except ProxyException as e: + except (ProxyException, SocksError) as e: raise ProxyException('Proxy connection error while fetching access token.') from e except (ClientError, DisconnectedError) as e: raise AuthConnectionException('{} while fetching access token.'.format(e.__class__.__name__)) from e diff --git a/aiopogo/exceptions.py b/aiopogo/exceptions.py index e3e921ca..4382cb77 100755 --- a/aiopogo/exceptions.py +++ b/aiopogo/exceptions.py @@ -1,9 +1,5 @@ from aiohttp import ProxyConnectionError from asyncio import TimeoutError -try: - from aiosocks import SocksError -except ImportError: - class SocksError(Exception): pass class AiopogoError(Exception): @@ -12,7 +8,7 @@ class AiopogoError(Exception): class HashServerException(AiopogoError): """Parent class of all hashing server errors""" -class ProxyException(ProxyConnectionError, SocksError): +class ProxyException(ProxyConnectionError): """Raised when there is an error connecting to a proxy server.""" class TimeoutException(AiopogoError, TimeoutError): diff --git a/aiopogo/hash_server.py b/aiopogo/hash_server.py index bd75bc76..c7608faa 100644 --- a/aiopogo/hash_server.py +++ b/aiopogo/hash_server.py @@ -21,7 +21,7 @@ class HashServer: - endpoint = "https://pokehash.buddyauth.com/api/v127_3/hash" + endpoint = "https://pokehash.buddyauth.com/api/v127_4/hash" status = {} _session = None loop = get_event_loop() diff --git a/aiopogo/rpc_api.py b/aiopogo/rpc_api.py index c628a1d7..7df6a10b 100755 --- a/aiopogo/rpc_api.py +++ b/aiopogo/rpc_api.py @@ -10,6 +10,10 @@ from protobuf_to_dict import protobuf_to_dict from aiohttp import ClientError, DisconnectedError, HttpProcessingError from pycrypt import pycrypt +try: + from aiosocks.errors import SocksError +except ImportError: + class SocksError(Exception): pass from .exceptions import * from .utilities import to_camel_case, get_time_ms, get_lib_path, IdGenerator, CustomRandom @@ -90,7 +94,7 @@ async def _make_rpc(self, endpoint, request_proto_plain): raise NianticOfflineException('{} Niantic server error: {}'.format(e.code, e.message)) else: raise UnexpectedResponseException('Unexpected RPC response: {}, '.format(e.code, e.message)) - except ProxyException as e: + except (ProxyException, SocksError) as e: raise ProxyException('Proxy connection error during RPC request.') from e except (TimeoutException, TimeoutError) as e: raise NianticTimeoutException('RPC request timed out.') from e diff --git a/setup.py b/setup.py index 922144cc..d7a18e23 100755 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ author = 'David Christenson', author_email='mail@noctem.xyz', description = 'Asynchronous Pokemon API lib', - version = '1.3.4', + version = '1.3.5', url = 'https://github.com/Noctem/aiopogo', packages = find_packages(), install_requires = [