Repository: PokemonGoF/PokemonGo-Bot

Issue:
KeyError: 'last_km_awarded' and UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position 1: ordinal not in range(128)
2016-10-10 16:24:11,415 [       cli] [INFO] PokemonGO Bot v1.0
2016-10-10 16:24:11,422 [       cli] [INFO] commit: 6d12193b
2016-10-10 16:24:11,428 [       cli] [INFO] Configuration initialized
2016-10-10 16:24:11,428 [pokemongo_bot.health_record.bot_event] [INFO] Health check is enabled. For more information:
2016-10-10 16:24:11,428 [pokemongo_bot.health_record.bot_event] [INFO] https://github.com/PokemonGoF/PokemonGo-Bot/tree/dev#analytics
2016-10-10 16:24:11,439 [requests.packages.urllib3.connectionpool] [INFO] Starting new HTTP connection (1): www.google-analytics.com
(19799) wsgi starting up on http://127.0.0.1:4000
[2016-10-10 16:24:11] [MainThread] [PokemonGoBot] [INFO] Setting start location.
[2016-10-10 16:24:11] [MainThread] [PokemonGoBot] [INFO] [x] Coordinates found in passed in location, not geocoding.
[2016-10-10 16:24:11] [MainThread] [PokemonGoBot] [INFO] Location found: -27.471975, 153.027360 (-27.471975, 153.02736, 8.0)
[2016-10-10 16:24:11] [MainThread] [PokemonGoBot] [INFO] Now at (-27.471975, 153.02736, 8.0)
[2016-10-10 16:24:11] [MainThread] [PokemonGoBot] [INFO] Login procedure started.
[2016-10-10 16:24:15] [MainThread] [PokemonGoBot] [INFO] Login successful.
[2016-10-10 16:24:15] [MainThread] [PokemonGoBot] [INFO] Found encrypt.so! Platform: linux2 encrypt.so directory: /root/PokemonGo-Bot
[2016-10-10 16:24:15] [MainThread] [PokemonGoBot] [INFO]
[2016-10-10 16:24:16] [MainThread] [PokemonGoBot] [INFO] [x] Error while opening cached forts: [Errno 2] No such file or directory: u'/root/PokemonGo-Bot/pokemongo_bot/../data/recent-forts-NAME.json'
[2016-10-10 16:24:16] [MainThread] [PokemonGoBot] [INFO] No inventory file /root/PokemonGo-Bot/pokemongo_bot/../web/inventory-NAME.json found. Creating a new one
[2016-10-10 16:24:16] [MainThread] [PokemonGoBot] [INFO] Level: 2 (Next Level: 1715 XP) (Total: 1285 XP)
[2016-10-10 16:24:16] [MainThread] [PokemonGoBot] [INFO] Pokemon Captured: 2 | Pokestops Visited: 0
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO]
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO] --- NAME ---
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO] Pokemon Bag: 2/250
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO] Items: 62/350
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO] Stardust: 200 | Pokecoins: 0
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO] PokeBalls: 58 | GreatBalls: 0 | UltraBalls: 0 | MasterBalls: 0
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO] RazzBerries: 0 | BlukBerries: 0 | NanabBerries: 0
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO] LuckyEgg: 0 | Incubator: 0 | TroyDisk: 0
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO] Potion: 0 | SuperPotion: 0 | HyperPotion: 0 | MaxPotion: 0
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO] Incense: 2 | IncenseSpicy: 0 | IncenseCool: 0
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO] Revive: 0 | MaxRevive: 0
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO]
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO] Pokemon:
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO] #7 Squirtle: (CP 13, IV 0.67)
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO] #129 Magikarp: (CP 10, IV 0.56)
[2016-10-10 16:24:18] [MainThread] [PokemonGoBot] [INFO]
[2016-10-10 16:24:18] [MainThread] [RandomAlivePause] [INFO] Next random alive pause at 17:35:05, for a duration of 0:02:09
[2016-10-10 16:24:18] [MainThread] [       cli] [INFO]
[2016-10-10 16:24:18] [MainThread] [       cli] [INFO] Ran for 0:00:07
[2016-10-10 16:24:18] [MainThread] [       cli] [INFO] Total XP Earned: 0  Average: 0.00/h
[2016-10-10 16:24:18] [MainThread] [       cli] [INFO] Travelled 0.00km
[2016-10-10 16:24:18] [MainThread] [       cli] [INFO] Visited 0 stops
[2016-10-10 16:24:18] [MainThread] [       cli] [INFO] Encountered 0 pokemon, 0 caught, 0 released, 0 evolved, 0 never seen before ()
[2016-10-10 16:24:18] [MainThread] [       cli] [INFO] Threw 0 pokeballs
[2016-10-10 16:24:18] [MainThread] [       cli] [INFO] Earned 0 Stardust
[2016-10-10 16:24:18] [MainThread] [       cli] [INFO] Hatched eggs 0
[2016-10-10 16:24:18] [MainThread] [       cli] [INFO]
[2016-10-10 16:24:18] [MainThread] [       cli] [INFO] Highest CP Pokemon:
[2016-10-10 16:24:18] [MainThread] [       cli] [INFO] Most Perfect Pokemon:
Traceback (most recent call last):
  File "pokecli.py", line 843, in <module>
    main()
  File "pokecli.py", line 191, in main
    bot = start_bot(bot, config)
  File "pokecli.py", line 146, in start_bot
    initialize_task(bot, config)
  File "pokecli.py", line 98, in initialize_task
    tree = TreeConfigBuilder(bot, config.raw_tasks).build()
  File "/root/PokemonGo-Bot/pokemongo_bot/tree_config_builder.py", line 80, in build
    instance = worker(self.bot, task_config)
  File "/root/PokemonGo-Bot/pokemongo_bot/base_task.py", line 23, in **init**
    self.initialize()
  File "/root/PokemonGo-Bot/pokemongo_bot/cell_workers/buddy_pokemon.py", line 73, in initialize
    self._check_old_reward()
  File "/root/PokemonGo-Bot/pokemongo_bot/cell_workers/buddy_pokemon.py", line 205, in _check_old_reward
    km_diff = self._km_walked() - self.buddy['last_km_awarded']
KeyError: 'last_km_awarded'
[2016-10-10 16:24:18] [MainThread] [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 "/root/PokemonGo-Bot/lib/python2.7/site-packages/raven/transport/threaded.py", line 174, in send_sync
    super(ThreadedHTTPTransport, self).send(data, headers)
  File "/root/PokemonGo-Bot/lib/python2.7/site-packages/raven/transport/http.py", line 47, in send
    ca_certs=self.ca_certs,
  File "/root/PokemonGo-Bot/lib/python2.7/site-packages/raven/utils/http.py", line 66, in urlopen
    return opener.open(url, data, timeout)
  File "/root/PokemonGo-Bot/lib/python2.7/site-packages/future/backports/urllib/request.py", line 494, in open
    response = self._open(req, data)
  File "/root/PokemonGo-Bot/lib/python2.7/site-packages/future/backports/urllib/request.py", line 512, in _open
    '_open', req)
  File "/root/PokemonGo-Bot/lib/python2.7/site-packages/future/backports/urllib/request.py", line 466, in _call_chain
    result = func(*args)
  File "/root/PokemonGo-Bot/lib/python2.7/site-packages/raven/utils/http.py", line 46, in https_open
    return self.do_open(ValidHTTPSConnection, req)
  File "/root/PokemonGo-Bot/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/lib64/python2.7/httplib.py", line 1017, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib64/python2.7/httplib.py", line 1051, in _send_request
    self.endheaders(body)
  File "/usr/lib64/python2.7/httplib.py", line 1013, in endheaders
    self._send_output(message_body)
  File "/usr/lib64/python2.7/httplib.py", line 862, in _send_output
    msg += message_body
UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position 1: ordinal not in range(128)
[2016-10-10 16:24:18] [MainThread] [sentry.errors.uncaught] [ERROR] [u"KeyError: 'last_km_awarded'", u'  File "pokecli.py", line 843, in <module>', u'  File "pokecli.py", line 191, in main', u'  File "pokecli.py", line 146, in start_bot', u'  File "pokecli.py", line 98, in initialize_task', u'  File "pokemongo_bot/tree_config_builder.py", line 80, in build', u'  File "pokemongo_bot/base_task.py", line 23, in __init__', u'  File "pokemongo_bot/cell_workers/buddy_pokemon.py", line 73, in initialize', u'  File "pokemongo_bot/cell_workers/buddy_pokemon.py", line 205, in _check_old_reward']



Discussion:
Same here. 

Ubuntu 16.

So did you edit your config.json with a text editor? Im on OS X and when I used the text editor the " that the editor uses is different (maybe a unicode " instead of ASCII, never looked too far into it). So make sure its an appropriate quote or that you're not missing a quote somewhere. Mine was easy to see because the offending quotes look italicized. I ended up just copying a quote I didn't edit and pasting it where I needed it. Hope that helps  


Resolving patch:
diff --git a/pokemongo_bot/cell_workers/buddy_pokemon.py b/pokemongo_bot/cell_workers/buddy_pokemon.py
--- a/pokemongo_bot/cell_workers/buddy_pokemon.py
+++ b/pokemongo_bot/cell_workers/buddy_pokemon.py
@@ -132,6 +132,9 @@ def work(self):
         if not self.buddy:
             return WorkerResult.SUCCESS
 
+        if not self.buddy.has_key('last_km_awarded'):
+            self.buddy['last_km_awarded'] = 0
+
         if self._km_walked() - self.buddy['last_km_awarded'] >= self.buddy_distance_needed:
             self.buddy['last_km_awarded'] += self.buddy_distance_needed
             if not self._get_award():


Test patch: