puntonim / promptastic

A fantastic prompt for Bash
http://painl.es/promptastic/
Apache License 2.0
81 stars 16 forks source link

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

Open martinschilliger opened 8 years ago

martinschilliger commented 8 years ago

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 commented 8 years ago

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 commented 7 years ago

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 commented 7 years ago

Cool! Thank you very much, it worked!