1.异常描述
1.环境描述
CM和CDP集群版本为7.1.4,Hue版本为4.5.0
2.问题描述
Hue使用编辑器提交中文内容报错'ascii' codec can't decode byte 0xe6 in position 3: ordinal not in range(128)
Hue Server报错日志如下:
代码语言:javascript复制Error running execute
Traceback (most recent call last):
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/desktop/libs/notebook/src/notebook/decorators.py", line 114, in wrapper
return f(*args, **kwargs)
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/desktop/libs/notebook/src/notebook/api.py", line 223, in execute
response = _execute_notebook(request, notebook, snippet)
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/desktop/libs/notebook/src/notebook/api.py", line 154, in _execute_notebook
response['handle'] = interpreter.execute(notebook, snippet)
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/desktop/libs/notebook/src/notebook/connectors/hiveserver2.py", line 96, in decorator
return func(*args, **kwargs)
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/desktop/libs/notebook/src/notebook/connectors/hiveserver2.py", line 300, in execute
handle = db.client.query(query, session=_session)
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/apps/beeswax/src/beeswax/server/hive_server2_lib.py", line 1285, in query
return self._client.execute_async_query(query, statement, session=session)
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/apps/beeswax/src/beeswax/server/hive_server2_lib.py", line 967, in execute_async_query
return self.execute_async_statement(statement=query_statement, confOverlay=configuration, session=session)
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/apps/beeswax/src/beeswax/server/hive_server2_lib.py", line 994, in execute_async_statement
(res, session) = self.call_return_result_and_session(self._client.ExecuteStatement, req, session=session)
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/apps/beeswax/src/beeswax/server/hive_server2_lib.py", line 730, in call_return_result_and_session
return self._call_return_result_and_session(fn, req, status=status, session=session)
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/apps/beeswax/src/beeswax/server/hive_server2_lib.py", line 762, in _call_return_result_and_session
res = fn(req)
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/desktop/core/src/desktop/lib/thrift_util.py", line 416, in wrapper
return attr(*args, **kwargs)
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/desktop/core/src/desktop/lib/thrift_util.py", line 485, in wrapper
ret = res(*args, **kwargs)
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/apps/beeswax/gen-py/TCLIService/TCLIService.py", line 324, in ExecuteStatement
self.send_ExecuteStatement(req)
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/apps/beeswax/gen-py/TCLIService/TCLIService.py", line 331, in send_ExecuteStatement
args.write(self._oprot)
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/apps/beeswax/gen-py/TCLIService/TCLIService.py", line 2009, in write
self.req.write(oprot)
File "/opt/cloudera/parcels/CDH-7.1.4-1.cdh7.1.4.p0.6300266/lib/hue/apps/beeswax/gen-py/TCLIService/ttypes.py", line 3967, in write
oprot.writeString(self.statement.encode('utf-8') if sys.version_info[0] == 2 else self.statement)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 38: ordinal not in range(128)
2.解决办法
1.在/opt/cloudera/parcels/CDH/lib/hue/build/env/lib/python2.7/site-packages目录下创建sitecustomize.py文件,编辑内容如下:
代码语言:javascript复制#encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
2.配置完之后,从CM重启Hue服务
3.重启之后,使用Hue编辑器提提交中文正常
3.总结
当前系统的Python版本为Python 2.7.5,而python2.x的默认编码是ascii,无法解析中文字符,解决方法是设置utf-8字符集。