Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
GeocodeFarm quota exceeded
"""
def mock_call_geocoder(*args, **kwargs):
return {
"geocoding_results": {
"STATUS": {
"access": "OVER_QUERY_LIMIT",
"status": "FAILED, ACCESS_DENIED"
}
}
}
with patch.object(self.geocoder, '_call_geocoder', mock_call_geocoder), \
self.assertRaises(exc.GeocoderQuotaExceeded):
self.geocoder.geocode('435 north michigan ave, chicago il 60611')
def _geocoder_exception_handler(self, error, message):
"""
LiveStreets-specific exceptions.
"""
if "no active subscriptions found" in message.lower():
raise GeocoderQuotaExceeded(message)
def _check_status(status):
"""
Validates error statuses.
"""
if status == 'ZERO_RESULTS':
# When there are no results, just return.
return
if status == 'OVER_QUERY_LIMIT':
raise GeocoderQuotaExceeded(
'The given key has gone over the requests limit in the 24'
' hour period or has submitted too many requests in too'
' short a period of time.'
)
elif status == 'REQUEST_DENIED':
raise GeocoderQueryError(
'Your request was denied.'
)
elif status == 'INVALID_REQUEST':
raise GeocoderQueryError('Probably missing address or latlng.')
else:
raise GeocoderQueryError('Unknown error.')
def _check_status(status):
"""
Validates error statuses.
"""
status_code = status['code']
if status_code == 429:
# Rate limit exceeded
raise GeocoderQuotaExceeded(
'The given key has gone over the requests limit in the 24'
' hour period or has submitted too many requests in too'
' short a period of time.'
)
if status_code == 200:
# When there are no results, just return.
return
if status_code == 403:
raise GeocoderQueryError(
'Your request was denied.'
)
else:
raise GeocoderQueryError('Unknown error.')
def _raise_for_error(self, body):
err = body.get('status')
if err:
code = err['value']
message = err['message']
# http://www.geonames.org/export/webservice-exception.html
if message.startswith("user account not enabled to use"):
raise GeocoderInsufficientPrivileges(message)
if code == 10:
raise GeocoderAuthenticationFailure(message)
if code in (18, 19, 20):
raise GeocoderQuotaExceeded(message)
raise GeocoderServiceError(message)
logger.log('Starting PokemonGo Bot....', 'green')
while True:
bot.tick()
except KeyboardInterrupt:
logger.log('Exiting PokemonGo Bot', 'red')
finished = True
report_summary(bot)
except (NotLoggedInException, ServerBusyOrOfflineException):
logger.log('[x] Error while connecting to the server, please wait %s minutes' % config.reconnecting_timeout, 'red')
time.sleep(config.reconnecting_timeout * 60)
except ServerSideRequestThrottlingException:
logger.log('Server is throttling, reconnecting in 30sec')
time.sleep(30)
except GeocoderQuotaExceeded:
logger.log('[x] The given maps api key has gone over the requests limit.', 'red')
finished = True
except:
# always report session summary and then raise exception
report_summary(bot)
raise
# When there are no results, just return.
return
if status == 1:
raise GeocoderServiceError(
'Internal server error.'
)
elif status == 2:
raise GeocoderQueryError(
'Invalid request.'
)
elif status == 3:
raise GeocoderAuthenticationFailure(
'Authentication failure.'
)
elif status == 4:
raise GeocoderQuotaExceeded(
'Quota validate failure.'
)
elif status == 5:
raise GeocoderQueryError(
'AK Illegal or Not Exist.'
)
elif status == 101:
raise GeocoderAuthenticationFailure(
'No AK'
)
elif status == 102:
raise GeocoderAuthenticationFailure(
'MCODE Error'
)
elif status == 200:
raise GeocoderAuthenticationFailure(