Repository: PokemonGoF/PokemonGo-Bot

Issue:
DeadlockWrap, TypeError: String or Integer object expected for key, unicode found 
<!--

STOP ! ! !

Read the following before creating anything (or you will have your issue/feature request closed without notice)

1. Please only create an ISSUE or a FEATURE REQUEST - don't mix the two together in one item
2. For a Feature Request please only fill out the FEATURE REQUEST section
3. For a Issue please only fill out the ISSUE section
4. Issues are NOT to be used for help/config problems/support - use the relevant slack channels as per the README
5. Provide a good summary in the title, don't just write problem, or awesome idea!
6. Delete all irrelevant sections not related to your issue/feature request (including this top section)

===============ISSUE SECTION===============

Before you create an Issue, please check the following:

1. Have you validated that your config.json is valid JSON? Use http://jsonlint.com/ to check.
2. Have you [searched our issue tracker](https://github.com/PokemonGoF/PokemonGo-Bot/issues?q=is%3Aissue+sort%3Aupdated-desc) to see if the issue already exists? If so, comment on that issue instead rather than creating a new issue.
3. Are you running on the `master` branch? We work on the `dev` branch and then add that functionality to `master` when it is stable. Your issue may be fixed on `dev` and there is no need for this issue, just wait and it will eventually be merged to `master`.
4. All Issue sections MUST be completed to help us determine the actual problem and find its cause
-->
### Expected Behavior

<!-- Tell us what you expect to happen -->

Bot running.
### Actual Behavior

<!-- Tell us what is happening -->

Error message, see traceback below
### Your FULL config.json (remove your username, password, gmapkey and any other private info)

<!-- Provide your FULL config file, feel free to use services such as pastebin.com to reduce clutter -->

http://pastebin.com/rGySE5GR
### Output when issue occurred

<!-- Provide a reasonable sample from your output log (not just the error message), feel free to use services such as pastebin.com to reduce clutter -->

2016-08-26 05:51:22,707 [       cli] [INFO] PokemonGO Bot v1.0
2016-08-26 05:51:22,707 [       cli] [INFO] commit: not found
2016-08-26 05:51:22,723 [       cli] [INFO] No config argument specified, checki
ng for /configs/config.json
2016-08-26 05:51:22,726 [       cli] [INFO] Configuration initialized
Traceback (most recent call last):
  File "pokecli.py", line 705, in <module>
    main()
  File "pokecli.py", line 103, in main
    bot = PokemonGoBot(config)
  File "D:\gamezone\pokebots\PokemonGo-Bot\pokemongo_bot__init__.py", line 106,
 in **init**
    if saved_info.has_key('client_id'):
  File "C:\Python27\lib\shelve.py", line 107, in has_key
    return key in self.dict
  File "C:\Python27\lib_abcoll.py", line 388, in **contains**
    self[key]
  File "C:\Python27\lib\bsddb__init__.py", line 270, in **getitem**
    return _DeadlockWrap(lambda: self.db[key])  # self.db[key]
  File "C:\Python27\lib\bsddb\dbutils.py", line 68, in DeadlockWrap
    return function(__args, *__kwargs)
  File "C:\Python27\lib\bsddb__init__.py", line 270, in <lambda>
    return _DeadlockWrap(lambda: self.db[key])  # self.db[key]
TypeError: String or Integer object expected for key, unicode found
### Steps to Reproduce

<!-- Tell us the steps you have taken to reproduce the issue -->

Run the bot
### Other Information

OS: 
Win7 64bit
Branch: 
dev
Git Commit: 
5e50264e7644b007dff7e0e057375cc433c36805
Python Version: 
Python 2.7.12 



Discussion:
I've added the full terminal output here http://pastebin.com/2QEd4g5H
commit: 0bedea3d78407b3313c3ceca90db1a156af63a08 still happening

I have the same error. 

2016-08-26 07:14:41,699 [       cli] [INFO] PokemonGO Bot v1.0
2016-08-26 07:14:41,707 [       cli] [INFO] commit: 5e50264e7644b007dff7e0e057375cc433c36805
2016-08-26 07:14:41,715 [       cli] [INFO] Configuration initialized
2016-08-26 07:14:41,716 [pokemongo_bot.health_record.bot_event] [INFO] Health check is enabled. For more information:
2016-08-26 07:14:41,716 [pokemongo_bot.health_record.bot_event] [INFO] https://github.com/PokemonGoF/PokemonGo-Bot/tree/dev#analytics
2016-08-26 07:14:41,725 [requests.packages.urllib3.connectionpool] [INFO] Starting new HTTP connection (1): www.google-analytics.com
Traceback (most recent call last):
  File "pokecli.py", line 705, in <module>
    main()
  File "pokecli.py", line 103, in main
    bot = PokemonGoBot(config)
  File "/home/karloowlim/PokemonGo-Bot/pokemongo_bot/**init**.py", line 106, in **init**
    if saved_info.has_key('client_id'):
  File "/usr/lib/python2.7/shelve.py", line 107, in has_key
    return key in self.dict
  File "/home/karloowlim/PokemonGo-Bot/lib/python2.7/_abcoll.py", line 388, in __contains__
    self[key]
  File "/usr/lib/python2.7/bsddb/**init**.py", line 270, in **getitem**
    return _DeadlockWrap(lambda: self.db[key])  # self.db[key]
  File "/usr/lib/python2.7/bsddb/dbutils.py", line 68, in DeadlockWrap
    return function(__args, *__kwargs)
  File "/usr/lib/python2.7/bsddb/__init__.py", line 270, in <lambda>
    return _DeadlockWrap(lambda: self.db[key])  # self.db[key]
TypeError: String or Integer object expected for key, unicode found
2016-08-26 07:14:42,184 [sentry.errors] [ERROR] Sentry responded with an error: 'utf8' codec can't decode byte 0x9c in position 1: invalid start byte (url: https://app.getsentry.com/api/90254/store/)
Traceback (most recent call last):
  File "/home/karloowlim/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/karloowlim/PokemonGo-Bot/local/lib/python2.7/site-packages/raven/transport/http.py", line 47, in send
    ca_certs=self.ca_certs,
  File "/home/karloowlim/PokemonGo-Bot/local/lib/python2.7/site-packages/raven/utils/http.py", line 66, in urlopen
    return opener.open(url, data, timeout)
  File "/home/karloowlim/PokemonGo-Bot/local/lib/python2.7/site-packages/future/backports/urllib/request.py", line 494, in open
    response = self._open(req, data)
  File "/home/karloowlim/PokemonGo-Bot/local/lib/python2.7/site-packages/future/backports/urllib/request.py", line 512, in _open
    '_open', req)
  File "/home/karloowlim/PokemonGo-Bot/local/lib/python2.7/site-packages/future/backports/urllib/request.py", line 466, in _call_chain
    result = func(*args)
  File "/home/karloowlim/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/karloowlim/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
  File "/home/karloowlim/PokemonGo-Bot/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x9c in position 1: invalid start byte
2016-08-26 07:14:42,186 [sentry.errors.uncaught] [ERROR] [u'TypeError: String or Integer object expected for key, unicode found', u'  File "pokecli.py", line 705, in <module>', u'  File "pokecli.py", line 103, in main', u'  File "pokemongo_bot/__init__.py", line 106, in **init**', u'  File "python2.7/shelve.py", line 107, in has_key', u'  File "python2.7/_abcoll.py", line 388, in __contains__', u'  File "bsddb/**init**.py", line 270, in **getitem**', u'  File "bsddb/dbutils.py", line 68, in DeadlockWrap', u'  File "bsddb/**init**.py", line 270, in <lambda>']
Fri Aug 26 07:14:42 PHT 2016 Pokebot  Stopped.
Press any button or wait 20 seconds to continue.

How to fix this?

Same here.

Same error here :(

Same here

same here :)

Quick and dirty workaround:

In pokemongo_bot/**init**.py, remove lines 104 to 112. 

That will at least allow the bot to run for now (might need to set enable_social to false as well, I haven't tested that).

Waiting on a proper solution.

In other words revert commit: dcda7a144508285dfc99d736aab75254bd489edc

Pretty much @Bilibox 

IMHO nothing mqtt-related should happen if enable_social = false. 

@Gobberwart No, removing lines 104-112 with enable_social = false should work fine. If you want to keep enable_social = true you have to revert social_handler.py back to self.mqttc = MyMQTTClass(bot)

I meant in general, not at the moment. No reason to have this stuff do anything if enable_social is false.

Currently, regardless of what enable_social is set to, this bit of code breaks everything. Since its only related to the social stuff, it shouldn't even be running if enable_social is false. 

But it is, so yeah just remove/comment those lines and it should work for now.

@solderzzc your thoughts?

Since init.py runs whether or not enable_social is true or false that's why it causes the error. With it set to false removing the lines from init.py fixes the problem.
With it set to true it then calls upon social_handler.py which then throws an error because of the added code. just needs to be fixed up and should be good. hopefully that explains it? 

That's exactly what I'm saying, mate :)

Just noting for _future reference_ that the code should be changed NOT to run if enable_social = false. 

Note that removing the lines was my suggestion, I'm not having trouble understanding it :)


Resolving patch:
diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py
--- a/pokemongo_bot/__init__.py
+++ b/pokemongo_bot/__init__.py
@@ -101,18 +101,16 @@ def __init__(self, config):
 
         self.capture_locked = False  # lock catching while moving to VIP pokemon
 
-        #client_id_file_path = os.path.join(_base_dir, 'data', 'mqtt_client_id')
-        #saved_info = shelve.open(client_id_file_path)
-        #if saved_info.has_key('client_id'):
-        #    self.config.client_id = saved_info['client_id']
-        #else:
-        #    client_uuid = uuid.uuid4()
-        #    self.config.client_id = str(client_uuid)
-        #    saved_info['client_id'] = self.config.client_id
-        #saved_info.close()
-        # There's issue report, just disable this part.
-        client_uuid = uuid.uuid4()
-        self.config.client_id = str(client_uuid)
+        client_id_file_path = os.path.join(_base_dir, 'data', 'mqtt_client_id')
+        saved_info = shelve.open(client_id_file_path)
+        key = 'client_id'.encode('utf-8')
+        if key in saved_info:
+            self.config.client_id = saved_info[key]
+        else:
+            self.config.client_id = str(uuid.uuid4())
+            saved_info[key] = self.config.client_id
+        saved_info.close()
+        
     def start(self):
         self._setup_event_system()
         self._setup_logging()


Test patch: