Repository: PokemonGoF/PokemonGo-Bot

Issue:
Dev branch: sudden break when arrived at Gym ...
Hi,

Not sure what happened.
My bot is "dev branch" that is cloned at 7/24 16:00 (TimeZone: +8)
It just breaks and restart to login ...

[2017-07-24 17:47:02] [GymPokemon] [INFO] Moving towards open Gym 春長鶴松 - 0.06km
[2017-07-24 17:47:05] [GymPokemon] [INFO] Moving towards open Gym 春長鶴松 - 0.06km
[2017-07-24 17:47:07] [GymPokemon] [INFO] Moving towards open Gym 春長鶴松 - 0.06km
[2017-07-24 17:47:10] [GymPokemon] [INFO] Moving towards open Gym 春長鶴松 - 0.05km
[2017-07-24 17:47:13] [GymPokemon] [INFO] Moving towards open Gym 春長鶴松 - 0.05km
[2017-07-24 17:47:15] [GymPokemon] [INFO] Moving towards open Gym 春長鶴松 - 0.05km
[2017-07-24 17:47:17] [GymPokemon] [INFO] Moving towards open Gym 春長鶴松 - 0.04km
[2017-07-24 17:47:21] [GymPokemon] [INFO] Moving towards open Gym 春長鶴松 - 0.04km
[2017-07-24 17:47:23] [GymPokemon] [INFO] Arrived at Gym 春長鶴松.
[2017-07-24 17:47:23] [       cli] [INFO] 
[2017-07-24 17:47:23] [       cli] [INFO] Ran for 0:01:25
[2017-07-24 17:47:23] [       cli] [INFO] Total XP Earned: 0  Average: 0.00/h
[2017-07-24 17:47:23] [       cli] [INFO] Travelled 0.07km
[2017-07-24 17:47:23] [       cli] [INFO] Visited 0 stops
[2017-07-24 17:47:23] [       cli] [INFO] Encountered 0 pokemon, 0 caught, 0 released, 0 evolved, 0 never seen before ()
[2017-07-24 17:47:23] [       cli] [INFO] Threw 0 pokeballs
[2017-07-24 17:47:23] [       cli] [INFO] Earned 0 Stardust
[2017-07-24 17:47:23] [       cli] [INFO] Hatched eggs 0
[2017-07-24 17:47:23] [       cli] [INFO] Next egg hatches in 0.45 km
[2017-07-24 17:47:23] [       cli] [INFO] 
[2017-07-24 17:47:23] [       cli] [INFO] Highest CP Pokemon: 
[2017-07-24 17:47:23] [       cli] [INFO] Most Perfect Pokemon: 
Traceback (most recent call last):
  File "pokecli.py", line 884, in <module>
    main()
  File "pokecli.py", line 206, in main
    bot.tick()
  File "/home/venney/project/pg03/pokemongo_bot/__init__.py", line 834, in tick
    if worker.work() == WorkerResult.RUNNING:
  File "/home/venney/project/pg03/pokemongo_bot/cell_workers/gym_pokemon.py", line 156, in work
    result = self.move_to_destination()
  File "/home/venney/project/pg03/pokemongo_bot/cell_workers/gym_pokemon.py", line 318, in move_to_destination
    formatted=("Arrived at Gym %s." % gym_name)
  File "/home/venney/project/pg03/pokemongo_bot/base_task.py", line 43, in emit_event
    data=data
  File "/home/venney/project/pg03/pokemongo_bot/event_manager.py", line 207, in emit
    l_event = Event(event, sender, level, formatted, data) 
  File "/home/venney/project/pg03/pokemongo_bot/event_manager.py", line 56, in __init__
    self.formatted = str(formatted).encode('utf-8', 'xmlcharrefreplace')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 15-18: ordinal not in range(128)
[2017-07-24 17:47:24] [sentry.errors] [ERROR] Sentry responded with an error: 'module' object has no attribute 'HTTPSHandler' (url: https://app.getsentry.com/api/90254/store/)
Traceback (most recent call last):
  File "/home/venney/project/pg03/local/lib/python2.7/site-packages/raven/transport/threaded.py", line 174, in send_sync
    super(ThreadedHTTPTransport, self).send(data, headers)
  File "/home/venney/project/pg03/local/lib/python2.7/site-packages/raven/transport/http.py", line 47, in send
    ca_certs=self.ca_certs,
  File "/home/venney/project/pg03/local/lib/python2.7/site-packages/raven/utils/http.py", line 44, in urlopen
    class ValidHTTPSHandler(urllib2.HTTPSHandler):
AttributeError: 'module' object has no attribute 'HTTPSHandler'
[2017-07-24 17:47:24] [sentry.errors.uncaught] [ERROR] [u"UnicodeEncodeError: 'ascii' codec can't encode characters in position 15-18: ordinal not in range(128)", u'  File "pokecli.py", line 884, in <module>', u'  File "pokecli.py", line 206, in main', u'  File "pokemongo_bot/__init__.py", line 834, in tick', u'  File "pokemongo_bot/cell_workers/gym_pokemon.py", line 156, in work', u'  File "pokemongo_bot/cell_workers/gym_pokemon.py", line 318, in move_to_destination', u'  File "pokemongo_bot/base_task.py", line 43, in emit_event', u'  File "pokemongo_bot/event_manager.py", line 207, in emit', u'  File "pokemongo_bot/event_manager.py", line 56, in __init__']
Mon Jul 24 17:47:24 CST 2017 Pokebot  Stopped.
Press any button or wait 6 seconds to continue.
  2017-07-24 17:47:30,814 [       cli] [INFO] PokemonGO Bot v1.0
2017-07-24 17:47:30,819 [       cli] [INFO] commit: 105b2695
2017-07-24 17:47:30,823 [       cli] [INFO] Configuration initialized



Discussion:
Can show us your config for gym pokemon?
This is not a config error. I noticed the error aswell. Gym name is 春長鶴松, whicht is not ascii. Event_mgr does some strange ascii conversion.
pals, I disabled GymPokemon.
Will wait for its availability ...
Thanks a lot. )

Resolving patch:
diff --git a/pokemongo_bot/event_manager.py b/pokemongo_bot/event_manager.py
--- a/pokemongo_bot/event_manager.py
+++ b/pokemongo_bot/event_manager.py
@@ -52,8 +52,11 @@ def __init__(self, event, sender=None, level='info', formatted='', data={}):
             self.sender = str(sender).encode('ascii', 'xmlcharrefreplace')
         
         self.level = str(level).encode('ascii', 'xmlcharrefreplace')
-        #self.formatted = str(formatted).encode('ascii', 'xmlcharrefreplace')
-        self.formatted = str(formatted).encode('utf-8', 'xmlcharrefreplace')
+
+        #Fixing issue 6123 for gym names that are in utf format.
+        self.formatted = str(formatted).encode('utf-8', 'ignore').decode('utf-8')
+        self.formatted = str(formatted).encode('ascii', 'xmlcharrefreplace')
+        
         self.data = str(data).encode('ascii', 'xmlcharrefreplace')
         self.friendly_msg = ""
         


Test patch: