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

Running script on headless terminal causes exception #19

Closed
GoogleCodeExporter opened this issue Aug 23, 2015 · 7 comments
Closed

Running script on headless terminal causes exception #19

GoogleCodeExporter opened this issue Aug 23, 2015 · 7 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Run script on Jenkins, on a remote slave.
2. or run script on a remote machine using ssh without the -t option.
3. hmmm. I suspect this will happen on any headless terminal, but I may be 
wrong.

What is the expected output? What do you see instead?
python gitinspector/gitinspector.py -f html -HTlr 
/scratch/jenkins/workspace/_foo1
Traceback (most recent call last):
  File "gitinspector/gitinspector.py", line 196, in <module>
    main()
  File "gitinspector/gitinspector.py", line 107, in main
    argv = terminal.convert_command_line_to_utf8()
  File "/scratch/jenkins/workspace/_foo1/gitinspector/terminal.py", line 117, in convert_command_line_to_utf8
    argv.append(arg.decode(sys.stdin.encoding, "replace"))
TypeError: decode() argument 1 must be string, not None

Note that on headless terminals, "None" is expected for sys.stdin.encoding:
python -c 'import sys; print sys.stdin.encoding'
None

What version of the product are you using? What version of Python? On what
operating system?
Python 2.6
Using gitinspector_0.3.1.zip

> uname -a
Linux localhost 3.7.10-101.fc17.x86_64 #1 SMP Wed Feb 27 19:14:22 UTC 2013 
x86_64 x86_64 x86_64 GNU/Linux
(But I can reproduce this on any headless non-windows OS terminal.)

Please provide any additional information below.
Let me know if you want me to try anything out for you. Thanks!

Original issue reported on code.google.com by gray...@gmail.com on 9 Nov 2013 at 1:00

@GoogleCodeExporter
Copy link
Author

Hi. I run gitinspector on many remote (headless systems) without a hitch. This 
just sounds to me like a misconfigured terminal? What does the following script 
return?:

import locale
import sys

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

Gitinspector uses unicode internally; so it needs a reference point in order to 
properly encode everything and anything into the right format.

It would be possible to just choose a default encoding when "None" is detected; 
I don't know if this is the "correct" solution, though.

Also, if you know the encoding, you could try executing something like the 
following on the terminal:

export PYTHONIOENCODING=utf-8; gitinspector.py <opts>

This forces sys.*.encoding into the encoding you specify. 

/Adam Waldenberg

Original comment by gitinspe...@ejwa.se on 9 Nov 2013 at 11:28

  • Changed state: Accepted
  • Added labels: Priority-Low
  • Removed labels: Priority-Medium

@GoogleCodeExporter
Copy link
Author

Here is the output:
print locale.getpreferredencoding() -> UTF-8
print sys.getdefaultencoding()      -> ascii
print sys.stdout.encoding           -> None
print sys.stdin.encoding            -> None

I tried the the following:
export PYTHONIOENCODING=utf-8

And it worked like a charm!
Jenkins is happy :)

Yeah, I don't know if the terminal is mis-configured, and I agree with you that 
it may not be the best assumption to set a default encoding if "None" is 
detected.  Maybe a potential "fix" is to detect "None" and tell the user to 
export the environment variable with the correct encoding.

Thanks for the quick response! Great tool!

Original comment by gray...@gmail.com on 11 Nov 2013 at 2:27

@GoogleCodeExporter
Copy link
Author

Great! Good thing that it worked.

I have been looking around a bit in order to somehow improve the behavior. A 
common solution seems to be to use the preferred encoding (if one is set). As 
you proposed, a warning on stderr is probably in order also; just to let the 
user know that something *might* be wrong with the settings of the terminal.

I'll keep this issue open until I have time to do something about it.

/Adam Waldenberg

Original comment by gitinspe...@ejwa.se on 15 Nov 2013 at 12:37

@GoogleCodeExporter
Copy link
Author

I'll try to improve this before the next release.

Original comment by gitinspe...@ejwa.se on 8 Jan 2014 at 2:48

  • Added labels: Milestone-Release0.3.2, Usability

@GoogleCodeExporter
Copy link
Author

This issue was closed by revision 23bc5fbbea90.

Original comment by gitinspe...@ejwa.se on 8 Jan 2014 at 5:06

  • Changed state: Fixed

@adam-waldenberg adam-waldenberg added this to the 0.3.2 milestone Aug 24, 2015
@adam-waldenberg adam-waldenberg self-assigned this Oct 9, 2015
cha5on referenced this issue Jul 7, 2016
This fix also sets the stdin encoding to UTF-8 whenever it is not set.
The behavior as the same as the one for stdout.
@meduzapat
Copy link

I also having this issue when the process runs detached:

Traceback (most recent call last): File "/usr/bin/gitinspector", line 9, in <module> load_entry_point('gitinspector==0.4.4', 'console_scripts', 'gitinspector')() File "/usr/lib/python2.7/dist-packages/gitinspector/gitinspector.py", line 105, in main argv = terminal.convert_command_line_to_utf8() File "/usr/lib/python2.7/dist-packages/gitinspector/terminal.py", line 122, in convert_command_line_to_utf8 argv.append(arg.decode(sys.stdin.encoding, "replace")) TypeError: decode() argument 1 must be string, not None
Was able to workaround adding export PYTHONIOENCODING=utf-8
:)

@neontapir
Copy link

neontapir commented Apr 18, 2017

Same. As a workaround, I updated my shell wrapper to do the export PYTHONIOENCODING=utf-8.

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

No branches or pull requests

4 participants