Repository: PokemonGoF/PokemonGo-Bot

Issue:
UnicodeDecodeError - can't decode byte 0x94 - invalid start byte
### Expected Behavior

Bot moves to fort
### Actual Behavior

Bot crashs with UnicodeDecodeError
### Your FULL config.json (remove your username, password, gmapkey and any other private info)

should not be the reason for the problem 
### Output when issue occurred

[2016-09-08 10:27:17] [       cli] [INFO]
[2016-09-08 10:27:17] [       cli] [INFO] Ran for 0:00:11
[2016-09-08 10:27:17] [       cli] [INFO] Total XP Earned: 0  Average: 0.00/h
[2016-09-08 10:27:17] [       cli] [INFO] Travelled 0.00km
[2016-09-08 10:27:17] [       cli] [INFO] Visited 0 stops
[2016-09-08 10:27:17] [       cli] [INFO] Encountered 0 pokemon, 0 caught, 0 released, 0 evolved, 0 never seen before ()
[2016-09-08 10:27:17] [       cli] [INFO] Threw 0 pokeballs
[2016-09-08 10:27:17] [       cli] [INFO] Earned 0 Stardust
[2016-09-08 10:27:17] [       cli] [INFO] Hatched eggs 0
[2016-09-08 10:27:17] [       cli] [INFO] Next egg hatches in 0.79 km
[2016-09-08 10:27:17] [       cli] [INFO]
[2016-09-08 10:27:17] [       cli] [INFO] Highest CP Pokemon:
[2016-09-08 10:27:17] [       cli] [INFO] Most Perfect Pokemon:
Traceback (most recent call last):
  File "C:_COMED\priv\PoGo\PokemonGo-Bot\pokecli.py", line 803, in <module>
    main()
  File "C:_COMED\priv\PoGo\PokemonGo-Bot\pokecli.py", line 162, in main
    bot.tick()
  File "C:_COMED\priv\PoGo\PokemonGo-Bot\pokemongo_bot__init__.py", line 685, in tick
    if worker.work() == WorkerResult.RUNNING:
  File "C:_COMED\priv\PoGo\PokemonGo-Bot\pokemongo_bot\cell_workers\move_to_fort.py", line 87, in work
    data=fort_event_data
  File "C:_COMED\priv\PoGo\PokemonGo-Bot\pokemongo_bot\base_task.py", line 43, in emit_event
    data=data
  File "C:_COMED\priv\PoGo\PokemonGo-Bot\pokemongo_bot\event_manager.py", line 76, in emit
    handler.handle_event(event, sender, level, formatted_msg, data)
  File "C:_COMED\priv\PoGo\PokemonGo-Bot\pokemongo_bot\event_handlers\logging_handler.py", line 140, in handle_event
    getattr(logger, level)(formatted_msg.encode(sys.stdout.encoding, "replace").decode("utf-8"))
  File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x94 in position 43: invalid start byte
### Steps to Reproduce

I have just to start the Bot. I think there is a fort in the near with an öäü character.
### Other Information

OS: 
Windows 10
Branch: 
dev
Git Commit: 
b66fc8854a5594370ecc6a52266251c1a7dc5e13
Python Version: 
Python 2.7.12



Discussion:
same here

```
Traceback (most recent call last):
  File "pokecli.py", line 803, in <module>
    main()
  File "pokecli.py", line 162, in main
    bot.tick()
  File "E:\Program Files\PokemonGo-Bot\pokemongo_bot\__init__.py", line 685, in tick
    if worker.work() == WorkerResult.RUNNING:
  File "E:\Program Files\PokemonGo-Bot\pokemongo_bot\cell_workers\move_to_fort.py", line 87, in work
    data=fort_event_data
  File "E:\Program Files\PokemonGo-Bot\pokemongo_bot\base_task.py", line 43, in emit_event
    data=data
  File "E:\Program Files\PokemonGo-Bot\pokemongo_bot\event_manager.py", line 76, in emit
    handler.handle_event(event, sender, level, formatted_msg, data)
  File "E:\Program Files\PokemonGo-Bot\pokemongo_bot\event_handlers\logging_handler.py", line 140, in handle_event
    getattr(logger, level)(formatted_msg.encode(sys.stdout.encoding, "replace").decode("utf-8"))
  File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x82 in position 41: invalid start byte

```

What is the encoding of your stout ? `print sys.stdout.encoding`

Had this too. Google Maps API has had too many requests from you due to restarting the bot too frequently. . Create a new one and replace the one in ./configs/auth.json (or by bash setup.sh create a new auth file

@fluxpiada Please create a ticket with your own issue and provide information's. This issue of for the decoding error.

@Anakin5: Do I need to put it in a particular part of the script or in general with a new interactive python command line? The two things I tried gave me: cp850. 

I am not an expert in Python, but I changed logging_handler.py  line 140 back to 
getattr(logger, level)(formatted_msg)
and it works at the moment for me :)


Resolving patch:
diff --git a/pokecli.py b/pokecli.py
--- a/pokecli.py
+++ b/pokecli.py
@@ -37,6 +37,9 @@
 import signal
 import string
 import subprocess
+
+codecs.register(lambda name: codecs.lookup("utf-8") if name == "cp65001" else None)
+
 from getpass import getpass
 from pgoapi.exceptions import NotLoggedInException, ServerSideRequestThrottlingException, ServerBusyOrOfflineException, NoPlayerPositionSetException
 from geopy.exc import GeocoderQuotaExceeded
@@ -127,7 +130,6 @@ def get_commit_hash():
             return f.read()[:8]
 
     try:
-        codecs.register(lambda name: codecs.lookup("utf-8") if name == "cp65001" else None)
         sys.stdout = codecs.getwriter('utf8')(sys.stdout)
         sys.stderr = codecs.getwriter('utf8')(sys.stderr)
 
diff --git a/pokemongo_bot/event_handlers/logging_handler.py b/pokemongo_bot/event_handlers/logging_handler.py
--- a/pokemongo_bot/event_handlers/logging_handler.py
+++ b/pokemongo_bot/event_handlers/logging_handler.py
@@ -137,4 +137,4 @@ def handle_event(self, event, sender, level, formatted_msg, data):
             formatted_msg = '[{}] {}'.format(event, formatted_msg)
 
         logger = logging.getLogger(type(sender).__name__)
-        getattr(logger, level)(formatted_msg.encode(sys.stdout.encoding, "replace").decode("utf-8"))
+        getattr(logger, level)(formatted_msg.encode(sys.stdout.encoding, "replace").decode("utf-8", "replace"))


Test patch: