Repository: PokemonGoF/PokemonGo-Bot

Issue:
HandleSoftBan makes bot crash
### Expected Behavior

When the bot finds nothing at a pokestop for two times consecutively, it should attempt at fixing the softban.  
### Actual Behavior

I jumped from Hong Kong to Ohio and I get the following output on running the bot.

``` bash
[20:46:03] Starting bot...
[20:46:04] Received level up reward: []
[20:46:04] Next egg incubates in 0.78 km
[20:46:06] Moving towards pokestop National Natural Landmark - 0.12km
[20:46:06] {'distance_unit': '', 'distance': '', 'current_position': (40.14959040264607, -83.02680305150429), 'last_position': (40.1495866, -83.0263423)}
[20:46:11] Moving towards pokestop National Natural Landmark - 0.08km
[20:46:11] {'distance_unit': '', 'distance': '', 'current_position': (40.149608280710524, -83.02727619068483), 'last_position': (40.14959040264607, -83.02680305150429)}
[20:46:15] Moving towards pokestop National Natural Landmark - 0.04km
[20:46:16] Arrived at fort.
[20:46:19] Found nothing in pokestop National Natural Landmark.
[20:46:19] Possibly searching too often, take a rest.
[20:46:19] Probably got softban.
[20:46:20] Moving towards pokestop Hawthorn - 0.08km
[20:46:20] {'distance_unit': '', 'distance': '', 'current_position': (40.149646315493364, -83.02826159112763), 'last_position': (40.149663, -83.027774)}2016-08-11 20:46:24,226 [       cli] [INFO] 
2016-08-11 20:46:24,226 [       cli] [INFO] Ran for 0:00:29
2016-08-11 20:46:24,226 [       cli] [INFO] Total XP Earned: 0  Average: 0.00/h
2016-08-11 20:46:24,226 [       cli] [INFO] Travelled 0.00km
2016-08-11 20:46:24,226 [       cli] [INFO] Visited 0 stops
2016-08-11 20:46:24,227 [       cli] [INFO] Encountered 0 pokemon, 0 caught, 0 released, 0 evolved, 0 never seen before
2016-08-11 20:46:24,227 [       cli] [INFO] Threw 0 pokeballs
2016-08-11 20:46:24,227 [       cli] [INFO] Earned 0 Stardust
2016-08-11 20:46:24,227 [       cli] [INFO] 
2016-08-11 20:46:24,227 [       cli] [INFO] Highest CP Pokemon: 
2016-08-11 20:46:24,227 [       cli] [INFO] Most Perfect Pokemon: 
Traceback (most recent call last):
  File "pokecli.py", line 514, in <module>
    main()
  File "pokecli.py", line 96, in main
    bot.tick()
  File "/home/slayslot/github/pokbot/nikhil/PokemonGo-Bot/pokemongo_bot/__init__.py", line 468, in tick
    if worker.work() == WorkerResult.RUNNING:
  File "/home/slayslot/github/pokbot/nikhil/PokemonGo-Bot/pokemongo_bot/cell_workers/handle_soft_ban.py", line 32, in work
    MoveToFort(self.bot, config=None).work()
  File "/home/slayslot/github/pokbot/nikhil/PokemonGo-Bot/pokemongo_bot/base_task.py", line 12, in __init__
    self.enabled = config.get('enabled', True)
AttributeError: 'NoneType' object has no attribute 'get'
2016-08-11 20:46:24,245 [sentry.errors] [ERROR] Sentry responded with an error: 'ascii' codec can't decode byte 0x9c in position 1: ordinal not in range(128) (url: https://app.getsentry.com/api/90254/store/)
Traceback (most recent call last):
  File "/home/slayslot/github/pokbot/nikhil/PokemonGo-Bot/local/lib/python2.7/site-packages/raven/transport/threaded.py", line 174, in send_sync
    super(ThreadedHTTPTransport, self).send(data, headers)
  File "/home/slayslot/github/pokbot/nikhil/PokemonGo-Bot/local/lib/python2.7/site-packages/raven/transport/http.py", line 47, in send
    ca_certs=self.ca_certs,
  File "/home/slayslot/github/pokbot/nikhil/PokemonGo-Bot/local/lib/python2.7/site-packages/raven/utils/http.py", line 66, in urlopen
    return opener.open(url, data, timeout)
  File "/home/slayslot/github/pokbot/nikhil/PokemonGo-Bot/local/lib/python2.7/site-packages/future/backports/urllib/request.py", line 494, in open
    response = self._open(req, data)
  File "/home/slayslot/github/pokbot/nikhil/PokemonGo-Bot/local/lib/python2.7/site-packages/future/backports/urllib/request.py", line 512, in _open
    '_open', req)
  File "/home/slayslot/github/pokbot/nikhil/PokemonGo-Bot/local/lib/python2.7/site-packages/future/backports/urllib/request.py", line 466, in _call_chain
    result = func(*args)
  File "/home/slayslot/github/pokbot/nikhil/PokemonGo-Bot/local/lib/python2.7/site-packages/raven/utils/http.py", line 46, in https_open
    return self.do_open(ValidHTTPSConnection, req)
  File "/home/slayslot/github/pokbot/nikhil/PokemonGo-Bot/local/lib/python2.7/site-packages/future/backports/urllib/request.py", line 1284, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/lib/python2.7/httplib.py", line 1057, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 1097, in _send_request
    self.endheaders(body)
  File "/usr/lib/python2.7/httplib.py", line 1053, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 895, in _send_output
    msg += message_body
UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position 1: ordinal not in range(128)
2016-08-11 20:46:24,246 [sentry.errors.uncaught] [ERROR] [u"AttributeError: 'NoneType' object has no attribute 'get'", u'  File "pokecli.py", line 514, in <module>', u'  File "pokecli.py", line 96, in main', u'  File "pokemongo_bot/__init__.py", line 468, in tick', u'  File "pokemongo_bot/cell_workers/handle_soft_ban.py", line 32, in work', u'  File "pokemongo_bot/base_task.py", line 12, in __init__']
Thu Aug 11 20:46:24 IST 2016 Pokebot  Stopped.
Press any button or wait 20 seconds to continue.
```
### Your config.json (remove your credentials and any other private info)

``` json
{
    "auth_service": "google",
    "username": "****",
    "password": "*****",
    "location": "40.14958661537503, -83.02634239196777",
    "gmapkey": "******",
    "libencrypt_location": "",
    "tasks": [
      {
        "type": "HandleSoftBan"
      },
      {
        "type": "CollectLevelUpReward"
      },
      {
        "type": "IncubateEggs",
        "config": {
          "longer_eggs_first": true
        }
      },
      {
        "type": "TransferPokemon"
      },
      {
        "type": "EvolvePokemon",
        "config": {
          "evolve_all": "NONE",
          "evolve_cp_min": 0,
          "evolve_speed": 5,
          "use_lucky_egg": false
        }
      },
      {
        "type": "RecycleItems",
        "config": {
          "item_filter": {
            "Pokeball":       { "keep" : 210 },
            "Potion":         { "keep" : 10 },
            "Super Potion":   { "keep" : 10 },
            "Hyper Potion":   { "keep" : 10 },
            "Revive":         { "keep" : 10 },
            "Razz Berry":     { "keep" : 100 }
          }
        }
      },
      {
        "type": "SpinFort"
      },
      {
        "type": "MoveToFort",
        "config": {
            "lure_attraction": true,
            "lure_max_distance": 2000
        }
      }
    ],
    "map_object_cache_time": 5,
    "forts": {
      "avoid_circles": true,
      "max_circle_size": 50
    },
    "websocket_server": false,
    "walk": 40,
    "action_wait_min": 1,
    "action_wait_max": 4,
    "debug": false,
    "test": false,
    "health_record": true,
    "location_cache": true,
    "distance_unit": "km",
    "reconnecting_timeout": 5,
    "catch_randomize_reticle_factor": 1.0,
    "catch_randomize_spin_factor": 1.0,
    "logging_color": true,
    "catch": {
      "any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"},
      "// Example of always catching Rattata:": {},
      "// Rattata": { "always_catch" : true }
    },
    "release": {
      "any": {"keep_best_cp": 1, "keep_best_iv": 1},
      "Caterpie":     { "release_below_cp": 100, "release_below_iv": 0.8, "logic": "and" },
      "Weedle":       { "release_below_cp": 100, "release_below_iv": 0.8, "logic": "and" },
      "Pidgey":       { "release_below_cp": 100, "release_below_iv": 0.8, "logic": "and" },
      "Rattata":      { "release_below_cp": 200, "release_below_iv": 0.8, "logic": "and" },
      "Spearow":      { "release_below_cp": 300, "release_below_iv": 0.8, "logic": "and" },
      "Ekans":        { "release_below_cp": 200, "release_below_iv": 0.8, "logic": "and" },
      "Zubat":        { "release_below_cp": 300, "release_below_iv": 0.8, "logic": "and" },
      "Magikarp":     { "release_below_cp": 145, "release_below_iv": 0.93, "logic": "or" }
    },
    "vips" : {
         "Any pokemon put here directly force to use Berry & Best Ball to capture, to secure the capture rate!": {},
        "any": {"catch_above_cp": 1200, "catch_above_iv": 0.9, "logic": "or" },
        "Lapras": {},
        "Moltres": {},
        "Zapdos": {},
        "Articuno": {},

        "// S-Tier pokemons (if pokemon can be evolved into tier, list the representative)": {},
        "Mewtwo": {},
        "Dragonite": {},
        "Snorlax": {},
        "// Mew evolves to Mewtwo": {},
        "Mew": {},
        "Arcanine": {},
        "Vaporeon": {},
        "Gyarados": {},
        "Exeggutor": {},
        "Muk": {},
        "Weezing": {},
        "Flareon": {}

    }
}

```
### Steps to Reproduce
1. Get a softban.
2. Run the bot near a pokestop. The bot will find the first pokestop and crash while going to the second one.
### Other Information

OS: Ubuntu 16.04 LTS
Git Commit: 138b66413e45efcef1ae015388b80a2725e7a7d8
Python Version: Python 2.7.12

Edit: Also, when I remove `HandleSoftBan` task from `config.json`, there's no crash. 



Discussion:
It's because of `MoveToFort(self.bot, config=None).work()`. It should be `MoveToFort(self.bot, config={}).work()` because `config` has to be existed to check `enable` feature whenever the bot ticks. I will open the PR later.

> It should be MoveToFort(self.bot, config={}).work()

@joaodragao Yup, I can confirm. It works now.


Resolving patch:
diff --git a/pokemongo_bot/cell_workers/handle_soft_ban.py b/pokemongo_bot/cell_workers/handle_soft_ban.py
--- a/pokemongo_bot/cell_workers/handle_soft_ban.py
+++ b/pokemongo_bot/cell_workers/handle_soft_ban.py
@@ -29,7 +29,7 @@ def work(self):
         )
 
         if fort_distance > Constants.MAX_DISTANCE_FORT_IS_REACHABLE:
-            MoveToFort(self.bot, config=None).work()
+            MoveToFort(self.bot, config={}).work()
             self.bot.recent_forts = self.bot.recent_forts[0:-1]
             if forts[0]['id'] in self.bot.fort_timeouts:
                 del self.bot.fort_timeouts[forts[0]['id']]


Test patch: