Bug #1352

Weboob doesn't support being launch from php program

Added by Damien e over 3 years ago. Updated about 3 years ago.

Status:Resolved Start:2014-02-12
Priority:Low Due date:
Assigned to:Laurent Bachelier % Done:

100%

Category:Applications / Console Spent time: -
Target version:1.0
Module: Branch:

Description

When I try to launch any weboob command via php :

$csv = shell_exec('/opt/local/bin/python /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/boobank list -f csv');

I get the following error in apache error log : /private/var/log/apache2/error_log

Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/boobank", line 5, in <module>
    pkg_resources.run_script('weboob==0.h', 'boobank')
  File "build/bdist.macosx-10.8-x86_64/egg/pkg_resources.py", line 492, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "build/bdist.macosx-10.8-x86_64/egg/pkg_resources.py", line 1350, in run_script
    execfile(script_filename, namespace, namespace)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/weboob-0.h-py2.7.egg/EGG-INFO/scripts/boobank", line 27, in <module>
    Boobank.run()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/weboob-0.h-py2.7.egg/weboob/tools/application/console.py", line 201, in run
    super(ConsoleApplication, klass).run(args)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/weboob-0.h-py2.7.egg/weboob/tools/application/base.py", line 423, in run
    app = klass()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/weboob-0.h-py2.7.egg/weboob/tools/application/repl.py", line 131, in __init__
    self.COPYRIGHT.encode(sys.stdout.encoding or locale.getpreferredencoding()),
LookupError: unknown encoding: 

I think neither sys.stdout.encoding or locale.getpreferredencoding() work in this context.

Commenting the line 131 of repl.py fixes the problem.

Associated revisions

Revision 19a95dc0d6a82e136401b73c12deb0e19b08958f
Added by Laurent Bachelier about 3 years ago

Centralize encoding guesses, default to UTF-8

This might not be enough for print() and could need a locale.setlocale()
even though it is generally discouraged.

closes #1352

History

Updated by Florent Fourcot over 3 years ago

Hello,

I cannot reproduce the bug on a Debian server. Calling weboob with a php script works (with apache).

You probably should have a look one your php installation, or set the locale in your script (maybe by prefixing weboob call with a locale setting, I'm not a php expert).

LANG=\"en_US.UTF8\"

Updated by Laurent Bachelier over 3 years ago

This happens if weboob can't detect the encoding, likely because there are no LANG (or LC_* ?) variables.

Maybe it should assume UTF-8 if there is none.

We use "locale.getpreferredencoding()" in a lot of places, and mostly as a fallback for sys.std*.encoding.

Updated by Damien e over 3 years ago

I use php on my Macbook. I can't remember if it's the package version with OS X or my own installation.

Adding export LANG=\"en_US.UTF8\"; before the call to weboob works. But I think this problem should be corrected in weboob like you said Laurent.

Updated by Laurent Bachelier over 3 years ago

  • Category set to Applications / Console
  • Assigned to set to Laurent Bachelier
  • Priority changed from Normal to Low
  • Target version set to 0.i

It would be merely for convenience, many applications will have the same issues without locales set.

Updated by Romain Bignon over 3 years ago

  • Target version changed from 0.i to 0.j

Updated by Florent Fourcot about 3 years ago

  • Status changed from New to To merge
  • Target version changed from 0.j to 1.0

Updated by Laurent Bachelier about 3 years ago

  • Status changed from To merge to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF