Repository: PokemonGoF/PokemonGo-Bot

Issue:
should_throttle_retry crash
Everything working fine, bot is walking then crashes to this. Happen multiple times so far.  Everything is up-to-date.

```
Traceback (most recent call last):
  File "pokecli.py", line 445, in <module>
    main()
  File "pokecli.py", line 71, in main
    bot.tick()
  File "C:\Trainers\PokemonGo-Bot01\pokemongo_bot\__init__.py", line 92, in tick
    if worker.work() == WorkerResult.RUNNING:
  File "C:\Trainers\PokemonGo-Bot01\pokemongo_bot\cell_workers\incubate_eggs.py", line 41, in work
    self._apply_incubators()
  File "C:\Trainers\PokemonGo-Bot01\pokemongo_bot\cell_workers\incubate_eggs.py", line 52, in _apply_incubators
    pokemon_id=egg["id"]
  File "c:\pokemongo-bot\src\pgoapi\pgoapi\pgoapi.py", line 84, in function
    return request.call()
  File "C:\Trainers\PokemonGo-Bot01\pokemongo_bot\api_wrapper.py", line 112, in call
    if should_throttle_retry:
UnboundLocalError: local variable 'should_throttle_retry' referenced before assignment
```



Discussion:
Same problem here
Traceback (most recent call last):
File "pokecli.py", line 446, in <module>
  main()
File "pokecli.py", line 71, in main
  bot.tick()
File "/home/mcpe/PokemonGo-Bot/pokemongo_bot/**init**.py", line 92, in tick
  if worker.work() == WorkerResult.RUNNING:
File "/home/mcpe/PokemonGo-Bot/pokemongo_bot/cell_workers/follow_spiral.py", line 92, in work 
  if step_walker.step():
File "/home/mcpe/PokemonGo-Bot/pokemongo_bot/step_walker.py", line 57, in step
  self.bot.heartbeat()
File "/home/mcpe/PokemonGo-Bot/pokemongo_bot/**init**.py", line 547, in heartbeat
  self.update_web_location()  # updates every tick
File "/home/mcpe/PokemonGo-Bot/pokemongo_bot/**init**.py", line 150, in update_web_location  
  gym_longitude=fort.get('longitude')
File "/home/mcpe/PokemonGo-Bot/src/pgoapi/pgoapi/pgoapi.py", line 84, in function
  return request.call()
File "/home/mcpe/PokemonGo-Bot/pokemongo_bot/api_wrapper.py", line 112, in call
if should_throttle_retry:
UnboundLocalError: local variable 'should_throttle_retry' referenced before assignment
When I try to restart it

[03:55:43]  Starting PokemonGo Bot.... 
[03:55:44]  [x] Current egg hatches in 1.85 km 
[03:55:45]  Not spinning any forts as there aren't enough space. You might want to change your config to recycle more items if this message appears consistently. 
[03:55:45]  Not moving to any forts as there aren't enough space. You might want to change your config to recycle more items if this message appears consistently. 
[03:55:45] Walking from (37.79550946193129, -122.40402303016896) to [37.79550946193129, -122.40402303016896] 0.00km
[03:55:46]  Not spinning any forts as there aren't enough space. You might want to change your config to recycle more items if this message appears consistently. 
[03:55:46]  Not moving to any forts as there aren't enough space. You might want to change your config to recycle more items if this message appears consistently. 
[03:55:46] Walking from (37.79550946193129, -122.40402303016896) to [37.796140240100854, -122.40402303016896] 0.07km
[03:55:55]  Not spinning any forts as there aren't enough space. You might want to change your config to recycle more items if this message appears consistently. 
[03:55:55]  Not moving to any forts as there aren't enough space. You might want to change your config to recycle more items if this message appears consistently. 
[03:56:04]  [x] Current egg hatches in 1.85 km 
[03:56:05]  Not spinning any forts as there aren't enough space. You might want to change your config to recycle more items if this message appears consistently. 
[03:56:05]  Not moving to any forts as there aren't enough space. You might want to change your config to recycle more items if this message appears consistently. 
[03:56:13]  Not spinning any forts as there aren't enough space. You might want to change your config to recycle more items if this message appears consistently. 
[03:56:13]  Not moving to any forts as there aren't enough space. You might want to change your config to recycle more items if this message appears consistently. 

Python 2.7.12
Ububtu 16.04 x64
4a1f6493a78ce246aac81f243d2f562f22880529

Same here, bot was farming with path file

```
Traceback (most recent call last):
  File "pokecli.py", line 446, in <module>
    main()
  File "pokecli.py", line 71, in main
    bot.tick()
  File ".../pokemongo_bot/__init__.py", line 92, in tick
    if worker.work() == WorkerResult.RUNNING:
  File ".../pokemongo_bot/cell_workers/follow_path.py", line 77, in work
    if step_walker.step():
  File ".../pokemongo_bot/step_walker.py", line 57, in step
    self.bot.heartbeat()
  File ".../pokemongo_bot/__init__.py", line 547, in heartbeat
    self.update_web_location()  # updates every tick
  File ".../pokemongo_bot/__init__.py", line 150, in update_web_location
    gym_longitude=fort.get('longitude')
  File ".../src/pgoapi/pgoapi/pgoapi.py", line 84, in function
    return request.call()
  File ".../pokemongo_bot/api_wrapper.py", line 112, in call
    if should_throttle_retry:
UnboundLocalError: local variable 'should_throttle_retry' referenced before assignment

```


Resolving patch:
diff --git a/pokemongo_bot/api_wrapper.py b/pokemongo_bot/api_wrapper.py
--- a/pokemongo_bot/api_wrapper.py
+++ b/pokemongo_bot/api_wrapper.py
@@ -100,10 +100,10 @@ def call(self, max_retry=15):
             request_timestamp = self.throttle_sleep()
             # self._call internally clear this field, so save it
             self._req_method_list = [req_method for req_method in api_req_method_list]
+            should_throttle_retry = False
+            should_unexpected_response_retry = False
             try:
                 result = self._call()
-                should_throttle_retry = False
-                should_unexpected_response_retry = False
             except ServerSideRequestThrottlingException:
                 should_throttle_retry = True
             except UnexpectedResponseException:
@@ -117,7 +117,7 @@ def call(self, max_retry=15):
                 continue # skip response checking
 
             if should_unexpected_response_retry:
-                unexpected_reponse_retry += 1
+                unexpected_response_retry += 1
                 if unexpected_response_retry >= 5:
                     logger.log('Server is not responding correctly to our requests.  Waiting for 30 seconds to reconnect.', 'red')
                     sleep(30)


Test patch: