Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

UnicodeDecodeError: 'ascii' codec can't decode byte 0xcc in position 68 #24

Open
martinschilliger opened this issue Feb 16, 2016 · 3 comments

Comments

@martinschilliger
Copy link

I have a problem, which I wasn't able to fix myself. If my directory i want to cd in contains german umlauts, then I got the error mentioned in the title:

$ cd /Users/Martin/Dropbox/Entwicklung/Bstäpp
Traceback (most recent call last):
  File "/Users/Martin/bin/promptastic/promptastic.py", line 186, in <module>
    write(prompt.render())
  File "/Users/Martin/bin/promptastic/promptastic.py", line 37, in render
    first_line = self._render_first_line()
  File "/Users/Martin/bin/promptastic/promptastic.py", line 65, in _render_first_line
    output += segment.render()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xcc in position 68: ordinal not in range(128)

Any idea where to encode de ascii-string in the promptastic.py? Thanks for your help!

@puntonim
Copy link
Owner

I could reproduce the bug, it is due to the particular a char in your dir named: Bstäpp.
I will take a look soon.
Thanks for reporting!

@mean-street
Copy link

Hi,
I had the same issue with 'é, è, à' in French, and found a quick way to fix it.
In the function get_valid_cwd() in utils.sys, try to replace :
cwd = os.getcwd()
by
cwd = os.getcwd().decode('utf-8')

I'm not 100% sure why it works though. The getcwd function returns a unicode object, which needs to be decoded. So I think that Python implicitly somehow does it, probably in ascii by default. With it, I force the string to be in UTF8.

I'll read more about encodings in python later, and I'll come back here if I find a clear explanation.
Hope this helped.

@martinschilliger
Copy link
Author

Cool! Thank you very much, it worked!

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

No branches or pull requests

3 participants