timwah / pokeslack

Get Slack messages posted to a #pokealert channel about rare Pokemon close to you
MIT License
38 stars 27 forks source link

Add some try catch logic around failed API requests #18

Open timwah opened 8 years ago

timwah commented 8 years ago
2016-07-28T22:24:59.468283+00:00 app[worker.1]: INFO:pokesearch:Completed  6.56% of scan.
2016-07-28T22:25:00.617325+00:00 app[worker.1]:   File "main.py", line 56, in <module>
2016-07-28T22:25:00.617343+00:00 app[worker.1]:     for pokemon in pokesearch.search(position, num_steps):
2016-07-28T22:25:00.617366+00:00 app[worker.1]:   File "/app/pokesearch.py", line 72, in search
2016-07-28T22:25:00.617315+00:00 app[worker.1]: Traceback (most recent call last):
2016-07-28T22:25:00.617514+00:00 app[worker.1]:     response_dict = self.api.call()
2016-07-28T22:25:00.617561+00:00 app[worker.1]:     response = request.request(api_endpoint, self._req_method_list, player_position)
2016-07-28T22:25:00.617706+00:00 app[worker.1]:     response_dict = self._parse_main_response(response, subrequests)
2016-07-28T22:25:00.617730+00:00 app[worker.1]:   File "/app/.heroku/src/pgoapi/pgoapi/rpc_api.py", line 201, in _parse_main_response
2016-07-28T22:25:00.617792+00:00 app[worker.1]:     response_proto_dict = self._parse_sub_responses(response_proto, subrequests, response_proto_dict)
2016-07-28T22:25:00.617518+00:00 app[worker.1]:   File "/app/.heroku/src/pgoapi/pgoapi/pgoapi.py", line 80, in call
2016-07-28T22:25:00.617657+00:00 app[worker.1]:   File "/app/.heroku/src/pgoapi/pgoapi/rpc_api.py", line 93, in request
2016-07-28T22:25:00.617811+00:00 app[worker.1]:   File "/app/.heroku/src/pgoapi/pgoapi/rpc_api.py", line 208, in _parse_sub_responses
2016-07-28T22:25:00.617867+00:00 app[worker.1]:     del response_proto_dict['returns']
2016-07-28T22:25:00.617909+00:00 app[worker.1]: KeyError: 'returns'
2016-07-28T22:25:00.760691+00:00 heroku[worker.1]: Process exited with status 1
2016-07-28T22:25:00.775516+00:00 heroku[worker.1]: State changed from up to crashed
me0wday commented 8 years ago

Seems to get stuck in this state too, have to restart the bot. edit: probably related https://www.reddit.com/r/pokemongodev/comments/4v3twy/request_throttling/

timwah commented 8 years ago

@thinkv Can you try the latest master? Put some additional retry logic there. Next step I think will be refining the REQ_SLEEP (time between requests) but it seems to be working fine for now.

me0wday commented 8 years ago

Still happening for me @timwah Seems to get stuck retrying after 10 retries. Could it be an authentication issue? I have to restart the app to get it going again. http://i.imgur.com/XvLlPJG.jpg