magnucki / gitinspector

Automatically exported from code.google.com/p/gitinspector
GNU General Public License v3.0
0 stars 0 forks source link

Script fails with exception when encountering UTF-8 character #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. run ./gitinspector.py script against repo with UTF-8 character in author's 
name

What is the expected output? What do you see instead?

raceback (most recent call last):
  File "./gitinspector.py", line 136, in <module>
    __run__.output()
  File "./gitinspector.py", line 57, in output
    outputable.output(changes.ChangesOutput(self.hard))
  File "/Users/tajima/Downloads/gitinspector/outputable.py", line 37, in output
    outputable.output_text()
  File "/Users/tajima/Downloads/gitinspector/changes.py", line 240, in output_text
    print(i.ljust(20)[0:20], end=" ")
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 8: 
ordinal not in range(128)

The person's name has a ü

What version of the product are you using? On what operating system?

Mac OS Snow Lion
 ./gitinspector.py  --version
gitinspector 0.2.2

Please provide any additional information below.

Original issue reported on code.google.com by johntaj...@gmail.com on 12 Jul 2013 at 10:26

GoogleCodeExporter commented 9 years ago
Thanks for the report. It "should" work just fine (TM) ;). It looks like it 
might be a terminal issue; the string itself is in UTF-8. Maybe something is 
causing it to fall back to ascii upon print?

Could you try running the following little script from your terminal?:

----

import locale
import sys

print locale.getpreferredencoding()
print sys.getdefaultencoding()
print sys.stdout.encoding
print sys.stdin.encoding

----

Tell me what output you get. My output is:

UTF-8
ascii
UTF-8
UTF-8

/Adam Waldenberg

Original comment by gitinspe...@ejwa.se on 12 Jul 2013 at 11:47

GoogleCodeExporter commented 9 years ago
Hi,
I got:

$ python
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> import sys
>>>
>>> print locale.getpreferredencoding()
US-ASCII
>>> print sys.getdefaultencoding()
ascii
>>> print sys.stdout.encoding
US-ASCII
>>> print sys.stdin.encoding
US-ASCII

Original comment by johntaj...@gmail.com on 12 Jul 2013 at 11:53

GoogleCodeExporter commented 9 years ago
So, looking into a bit further, on my system I have:

$ locale
LANG="en_CA.US-ASCII"
LC_COLLATE="en_CA.US-ASCII"
LC_CTYPE="en_CA.US-ASCII"
LC_MESSAGES="en_CA.US-ASCII"
LC_MONETARY="en_CA.US-ASCII"
LC_NUMERIC="en_CA.US-ASCII"
LC_TIME="en_CA.US-ASCII"
LC_ALL=

So, then I did a bit of looking up and I'm supposed to add the following to my 
.bash_login:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

When I do that, running your little script I get this now:

$ python
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> import sys
>>>
>>> print locale.getpreferredencoding()
UTF-8
>>> print sys.getdefaultencoding()
ascii
>>> print sys.stdout.encoding
UTF-8
>>> print sys.stdin.encoding
UTF-8
>>>

Now it's working fine.

Thanks for your help and super fast response!! :)

Original comment by johntaj...@gmail.com on 12 Jul 2013 at 12:00

GoogleCodeExporter commented 9 years ago
Aha. So that is the problem then. The easiest fix is to switch terminal 
encoding to UTF-8.

Take a look at this post (seems to be a common issue):
http://yzisin.wordpress.com/2012/01/09/how-to-fix-locale-issues-in-mac-os-x-lion
-terminal/

You could also try to just run the following before starting gitinspector; if 
it behaves anything like a normal unix terminal it should also work:

LANG=en_US.UTF-8

/Adam Waldenberg

Original comment by gitinspe...@ejwa.se on 12 Jul 2013 at 12:13

GoogleCodeExporter commented 9 years ago
I see that you beat me to it :). Great that it is working.

/Adam Waldenberg

Original comment by gitinspe...@ejwa.se on 12 Jul 2013 at 12:14

GoogleCodeExporter commented 9 years ago
Marking as Semi-Invalid as it's not really an issue in gitinspector. However, 
some kind of fix or improvement could be added to help alleviate the problems 
caused by a non-unicode terminal encoding.

/Adam Waldenberg 

Original comment by gitinspe...@ejwa.se on 12 Jul 2013 at 12:26

GoogleCodeExporter commented 9 years ago
Issue 54 has been merged into this issue.

Original comment by gitinspe...@ejwa.se on 27 Dec 2014 at 6:23