zanata-python-client: need better error message for unexpected html response
Description
Environment
is cloned by
relates to
Activity

Sean Flanigan 26 February 2016 at 07:26
Apparently the redirection is broken at present: a URL like https://translate.stage.zanata.org/zanata/rest/projects/p/pahuang-training/iterations/i/master/locales is being redirected to https://translate.stage.zanata.org/ instead of https://translate.stage.zanata.org/rest/projects/p/pahuang-training/iterations/i/master/locales (as intended).
So right now, a request for https://translate.stage.zanata.org/zanata/rest/projects/p/pahuang-training/iterations/i/master/locales is actually returning the home page's HTML, and 's report is really about the handling of that situation.
I would suggest that the client should detect invalid responses (bad media type such as HTML) and generate a meaningful error message to the user: perhaps something like:
Invalid media type (text/html <or whatever was received>) in REST response. Please check that the server URL is correct, including the protocol (http/https). If the URL is correct, there may be a configuration problem on the server.

Sean Flanigan 26 February 2016 at 07:18Edited
Apparently the redirection is broken at present: a URL like https://translate.stage.zanata.org/zanata/rest/projects/p/pahuang-training/iterations/i/master/locales is being redirected to https://translate.stage.zanata.org/ instead of https://translate.stage.zanata.org/rest/projects/p/pahuang-training/iterations/i/master/locales (as intended).

Sean Flanigan 25 February 2016 at 06:32
The http library probably just needs to be told to follow redirects when performing its GETs; then the client code won't have to deal with 302 responses. eg http://bitworking.org/projects/httplib2/doc/html/libhttplib2.html#id1
Also, I noticed that line 65 in zanataclient/zanatalib/service.py is catching the exception, logging it, and then returning rst (which is None). The actual traceback above is just a consequence of the earlier exception handling. I suggest that it should propagate the exception (so as to fail fast in an unrecoverable situation), or at least log the traceback before continuing.
Details
Details
Assignee

Reporter

Components
Fix versions
Affects versions
Priority

Soon, https;//translate.zanata.org/zanata/ will be shorten as
https://translate.zanata.org/ by using HTTP 301 (Moved Permanently).
However zanata-python-client failed to handled this:
Steps to repoduced:
1. Get zanata.xml from https://translate.stage.zanata.org/iteration/view/selinux-coloring-book/selinux-coloring-book
2. Change url to " https://translate.stage.zanata.org/zanata/" in
both zanata.xml and ~/.config/zanata.ini
3. zanata pull
Actual:
[INFO] Loading zanata project config from: /tmp/selinux-color-book/zanata.xml
[INFO] Loading zanata user config from: /home/dchen/.config/zanata.ini
[INFO] zanata server: https://translate.stage.zanata.org/zanata
Exception while decoding No JSON object could be decoded its may due to file already exists on the server or not a PO file
Exception while decoding No JSON object could be decoded its may due to file already exists on the server or not a PO file
Traceback (most recent call last):
File "/usr/bin/zanata", line 25, in <module>
zanata.run()
File "/usr/lib/python2.7/site-packages/zanataclient/zanata.py", line 756, in run
program_name=os.path.split(sys.argv[0])[1],
File "/usr/lib/python2.7/site-packages/zanataclient/command.py", line 348, in handle_program
command(command_options, args)
File "/usr/lib/python2.7/site-packages/zanataclient/zanata.py", line 385, in run_func
context_data = ProjectContext(command_options, mode).get_context_data()
File "/usr/lib/python2.7/site-packages/zanataclient/context.py", line 291, in get_context_data
[method() for method in build_configs]
File "/usr/lib/python2.7/site-packages/zanataclient/context.py", line 321, in build_remote_config
[method() for method in build_remote_config]
File "/usr/lib/python2.7/site-packages/zanataclient/context.py", line 223, in _update_locale_mapping
locale_map = self.process_locales(locales)
File "/usr/lib/python2.7/site-packages/zanataclient/context.py", line 247, in process_locales
if len(locales) > 0:
TypeError: object of type 'NoneType' has no len()
Expected:
Pull without problem