vj57 / googlecl

Automatically exported from code.google.com/p/googlecl
0 stars 0 forks source link

Encoding issues when running without terminal #360

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a contact containing a non-ascii character (e.g. "Jörg")
2. Add cronjob "googlecl contacts list --fields='name' --title=''"

What is the expected output? What do you see instead?
googlecl should use the character encoding from the environment (utf-8), 
instead it uses sys.getdefaultencoding() which defaults to ascii and results in 
\x encoded strings.

What version of the product are you using? On what operating system? What 
version of gdata-python-client (aka python-gdata)?
googlecl 0.9.12-1 from .deb on Debian squeeze, python-gdata 2.0.8-1.1.

Please provide any additional information below.
Replacing the line return_enc = sys.getdefaultencoding() in __init__.py by 
something like return_enc = 'utf-8' yields exspected results. I'm no python 
guru so I don't know which function call would result in the encoding that e.g. 
locale knows about.
However, if everything else fails I would welcome a config variable to be used 
("fallback_terminal_encoding"?) in case the encoding can not be automatically 
determined.

Original issue reported on code.google.com by eckho...@gmail.com on 8 Feb 2011 at 10:36

GoogleCodeExporter commented 9 years ago
I just went right for the config file :)

Try applying this patch and adding an option called "default_encoding = utf-8" 
to the GENERAL section of your config file (~/.config/googlecl/config). Please 
let me know if it does or does not work.

Original comment by tom.h.mi...@gmail.com on 14 Feb 2011 at 1:17

Attachments:

GoogleCodeExporter commented 9 years ago
Unfortunately, there appears to be something wrong with that patch:

Traceback (most recent call last):
  File "/usr/bin/google", line 54, in <module>
    import googlecl
  File "/usr/lib/pymodules/python2.6/googlecl/__init__.py", line 70, in <module>
    TERMINAL_ENCODING = determine_terminal_encoding()
  File "/usr/lib/pymodules/python2.6/googlecl/__init__.py", line 52, in determine_terminal_encoding
    return_enc = googlecl.config.parser.safe_get('GENERAL',
AttributeError: 'module' object has no attribute 'safe_get'

Original comment by eckho...@gmail.com on 14 Feb 2011 at 9:39

GoogleCodeExporter commented 9 years ago
Whoops. This patch (applied to 0.9.12) should actually fix the problem.  If you 
applied the patch from comment 1, you'll have to remove it.

There may be some garbled characters as GoogleCL gets started, but the output 
you want from the cron job should come through.

Again, let me know if something's wrong. Thanks for the quick report turnaround!

Original comment by tom.h.mi...@gmail.com on 17 Feb 2011 at 3:21

Attachments:

GoogleCodeExporter commented 9 years ago
Hey. Thanks again for your effort. However, it seems when 
determine_terminal_encoding is called on module initialization (without config) 
something goes wrong now.

Traceback (most recent call last):
  File "/usr/bin/google", line 54, in <module>
    import googlecl
  File "/usr/lib/pymodules/python2.6/googlecl/__init__.py", line 75, in <module>
    TERMINAL_ENCODING = determine_terminal_encoding()
  File "/usr/lib/pymodules/python2.6/googlecl/__init__.py", line 55, in determine_terminal_encoding
    if not return_enc:
UnboundLocalError: local variable 'return_enc' referenced before assignment

When I add "return_enc = 'utf-8'" before "if config is not None" (to see what 
happens when the function is called the second time) I get this:

Traceback (most recent call last):
  File "/usr/bin/google", line 839, in <module>
    main()
  File "/usr/bin/google", line 825, in main
    run_once(options, args)
  File "/usr/bin/google", line 530, in run_once
    options.config)
  File "/usr/bin/google", line 354, in import_service
    config = googlecl.config.load_configuration(config_file_path)
  File "/usr/lib/pymodules/python2.6/googlecl/config/__init__.py", line 89, in load_configuration
    googlecl.TERMINAL_ENCODING = googlecl.determine_terminal_encoding(config)
  File "/usr/lib/pymodules/python2.6/googlecl/__init__.py", line 54, in determine_terminal_encoding
    return_enc = config.parser.safe_get('GENERAL',
AttributeError: ConfigParser instance has no attribute 'safe_get'

Original comment by eckho...@gmail.com on 22 Feb 2011 at 10:58

GoogleCodeExporter commented 9 years ago
Thanks for your patience with this. I've heard the third time is the charm, so 
here's the third version of that patch (again applied to 0.9.12 directly).

(Your instinct with return_enc was right, but unfortunately I had a typo with 
the config code, also fixed in this patch)

Original comment by tom.h.mi...@gmail.com on 9 Mar 2011 at 3:40

Attachments:

GoogleCodeExporter commented 9 years ago
Your latest patch indeed fixes the issue. Thanks.

Original comment by eckho...@gmail.com on 13 Mar 2011 at 6:38

GoogleCodeExporter commented 9 years ago
Finally! Sorry for all the botched attempts.

Closed by r542.

Original comment by tom.h.mi...@gmail.com on 18 Mar 2011 at 12:51