Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: a bytes-like object is required, not 'str' #45

Open
UltimatePancake opened this issue May 21, 2017 · 2 comments
Open

TypeError: a bytes-like object is required, not 'str' #45

UltimatePancake opened this issue May 21, 2017 · 2 comments

Comments

@UltimatePancake
Copy link

 I  ~/.config/habitica  habitica --debug status                                                                                                                                                                            3359ms
DEBUG:root:Command line args: {'--version': 'False', '--help': 'False', '<command>': 'status', '<args>': '[]', '--difficulty': 'easy', '--verbose': 'False', '--debug': 'True', '--checklists': 'False'}
DEBUG:root:Loading habitica auth data from /home/pancake/.config/habitica/auth.cfg
DEBUG:root:Loading cached config data (/home/pancake/.config/habitica/cache.cfg)...
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): habitica.com
DEBUG:requests.packages.urllib3.connectionpool:https://habitica.com:443 "GET /api/v3/user HTTP/1.1" 200 None
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): habitica.com
DEBUG:requests.packages.urllib3.connectionpool:https://habitica.com:443 "GET /api/v3/groups?type=party HTTP/1.1" 200 206
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): habitica.com
DEBUG:requests.packages.urllib3.connectionpool:https://habitica.com:443 "GET /api/v3/groups/523d2eb1-9944-4286-a9a5-c4493fbe0a0e HTTP/1.1" 200 None
INFO:root:Updating quest information...
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): habitica.com
DEBUG:requests.packages.urllib3.connectionpool:https://habitica.com:443 "GET /api/v3/content HTTP/1.1" 200 None
DEBUG:root:	On a boss/hp type of quest
DEBUG:root:Updating (and caching) config data (/home/pancake/.config/habitica/cache.cfg)...
DEBUG:root:Loading cached config data (/home/pancake/.config/habitica/cache.cfg)...
Traceback (most recent call last):
  File "/home/pancake/.local/bin/habitica", line 13, in <module>
    habitica.cli()
  File "/home/pancake/.local/lib/python3.6/site-packages/habitica/core.py", line 335, in cli
    quest_title=str(quest_title))
  File "/home/pancake/.local/lib/python3.6/site-packages/habitica/core.py", line 115, in update_quest_cache
    cache.write(f)
  File "/usr/lib/python3.6/configparser.py", line 916, in write
    self._defaults.items(), d)
  File "/usr/lib/python3.6/configparser.py", line 923, in _write_section
    fp.write("[{}]\n".format(section_name))
TypeError: a bytes-like object is required, not 'str'

@KIAaze
Copy link

KIAaze commented Dec 14, 2017

I had the same issue. It only seems to be happening when cache.cfg is missing, i.e. to any new user.
I fixed it by simply disabling binary writing. Hopefully that does not break anything else, in particular any unicode encoded tasks or similar... I failed to make configparser work with unicode section, key, values.
It works fine for me so far.

Here is a patch:

diff --git a/habitica/core.py b/habitica/core.py
index 980dfad..9c2c18d 100755
--- a/habitica/core.py
+++ b/habitica/core.py
@@ -111,7 +111,7 @@ def update_quest_cache(configfile, **kwargs):
     for key, val in kwargs.items():
         cache.set(SECTION_CACHE_QUEST, key, val)
 
-    with open(configfile, 'wb') as f:
+    with open(configfile, 'w') as f:
         cache.write(f)
 
     cache.read(configfile)


@KIAaze
Copy link

KIAaze commented Dec 14, 2017

Already fixed by this pull request #36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants