斯潘8
第4页
你好,
ListKeyValuePairExtractor componant遇到了一个新问题,对于某些数据,它遇到了编码错误:
Python异常:'ascii'编解码器无法解码位置12中的字节0xa0:序号不在范围(128)回溯(最近的调用最后一次):文件“ ”,第30行,输入文件“ ”,第118行,在get_list_attribute_namesUnicodeDecodeError中:“ascii”编解码器无法解码位置12中的字节0xa0:序号不在范围内(128)调用方法“input”f_60(PythonFactory)时遇到错误:PythonFactory无法处理特征发生了致命错误。请检查上面的日志文件,以了解调用方法“input”f_42(PythonFactory)时遇到的详细错误:PythonFactory无法处理feature发生了致命错误。有关详细信息,请查看上面的日志文件
我做了很多事情,对utf-8或windows-1252上的所有属性进行编码,我尝试过用这个regex([^\w\S”]{0,2}$)的stringreplacer。但不管怎样,还是一样的问题,ListKeyValuePairExtractor上的作业停止了。
任何想法如何解决或忽略这些错误并继续处理其他事情?
谨致问候,
尼古拉斯
有人有幸修好这个吗?我们也遇到过类似的问题,希望@Sander.可能能够帮助解决。
transformer执行我们希望它做的事情,并且可以让一些特性运行,但是它会导致工作区失败。
以下是包含相关错误的日志文件摘录:
2019-12-31 13:57:24 | 2.6 | 0.1 | | Python Excepti提出警告on: local variable 'error' referenced before assignment 2019-12-31 13:57:24| 2.6| 0.0|WARN |Traceback (most recent call last): File " ", line 63, in input UnboundLocalError: local variable 'error' referenced before assignment 2019-12-31 13:57:24| 2.6| 0.0|ERROR |Error encountered while calling method `input' 2019-12-31 13:57:24| 2.6| 0.0|FATAL |ListKeyValuePairExtractor_PythonCaller (PythonFactory): PythonFactory failed to process feature
(谢谢你的标记我,@david_r.!)
嗨@nmeriotdev公司/尼古拉斯,
很抱歉听到您在使用“我的”ListKeyValuePairExtractor时遇到的问题!
我在一些特殊的字符/编码上做了测试,但是有了这些东西,很难捕捉到所有的情况。。。
你介意向我发送你的工作区和一些测试数据吗?我可以希望重现问题并改进/修复ListKeyValuePailextractor?当我现在很忙,我可能需要1-2周左右......
你可以尝试大卫的建议,但我怀疑他们是否会工作。该解码()功能转换A.一串into aunicode码对象,但是字首and后缀对象可能是类型unicode码已经。相反,我期待着attr对象应解码为unicode码对象,所以以。。开始()andendswith()将在同一类型的对象上调用函数。
我们可以尝试的第一件事是将FME从Python 2.7切换到3.x(工作区参数>脚本> Python兼容性)。如果您安装了3.x并有选择使用它,即。Python 3.x的优势,就是unicode码type no longer exists and that it always compares通过tes对象。
如果3.x不适合您,可以按如下方式更改代码:
def get_list_attribute_names(self,feature,pattern):prefix,suffix = pattern属性= feature.getAlTTRIBUTENAMES()#获取所有属性名称结果_LIST = [] for attr in属性:#过滤从attr = attr.decode('Cp1252')如果attr.startswith(prefix)和attr.endswith(后缀):index = self.regex1.findall(attr)[ - 1]#获取最后一个号码(= list index)结果_list.append((index,attr))返回排序(结果_list)
正如David已经提到的,您可能需要在这里使用精确的编码。
FME在第40行左右的日志文件中说了什么?例如,在我的机器上,它显示:
Operating System: Microsoft Windows 10 64-bit (Build 16299)
FME平台:WIN32
locale:en_gb.
代码页:1252(ANSI-拉丁语I)
或者,您还可以更改此行(从上面的代码示例中):
attr = attr.decode('cp1252')
进入:
属性=属性解码('cp1252',errors='ignore')
这将简单地告诉Python忽略它无法解码的任何字节。实际上是一个糟糕的解决方案,但至少你的工作空间在这里不再崩溃了。
如果这也不起作用(即工作区仍然崩溃),您可以替换获取\列表\属性\名称()这段代码的作用是:
def get_list_attribute_names(self, feature, pattern): prefix, suffix = pattern attributes = feature.getAllAttributeNames() # get all attribute names result_list = [] for attr in attributes: # filter out the attributes we need try: if attr.startswith(prefix) and attr.endswith(suffix): index = self.regex1.findall(attr)[-1] # gets the last number (= list index) result_list.append((index, attr))
除unicodeerror之外:传递返回排序(结果_list)
不过,这只是暂时的解决办法。我很乐意适当地修复ListKeyValuePairExtractor。。。
我希望你能在这里分享你的(部分)工作区+数据。
如果您是代码的作者,我将推荐将Python解释器更改为3.6+。它默认为Unicode字符。
来自__future__导入unicode_literals如果你做到了,你可以做到
from __future__ import absolute_import, division, print_function, unicode_literalswhich makes it compatible with python 3.
远程调试很难:-)
Try the following instead:
前缀,后缀=模式前缀=前缀.解码('cp1252')后缀=后缀.解码('cp1252')
回溯(最近呼叫最后一个呼叫):文件“”,第30行,在输入文件“ ”,行120中,在get_list_attribute_names中:'ASCII'编解码器无法解码位置12中的字节0xA0:序数不是在调用方法`输入'f_56(pythonfactory)时遇到的范围(128)错误:pythonfactory无法处理功能,发生了致命错误。检查上面的日志文件以获取在调用方法`输入'时遇到的详细信息错误
key_attr = feature.getAttribute('__ key_attr'.decode('cp1252'))
您需要右键单击自定义转换器并选择“编辑”。
自定义转换器将在FME Workbench的新实例中打开,您可以在其中编辑PythonCaller。保存自定义转换器时,最简单的方法是不更改转换器版本号(保存前将询问您)。
Python Exception: 'tuple' object has no attribute 'decode' Traceback (most recent call last): File " ", line 30, in input File " ", line 113, in get_list_attribute_names AttributeError: 'tuple' object has no attribute 'decode' Error encountered while calling method `input' f_42(PythonFactory): PythonFactory failed to process feature A fatal error has occurred. Check the logfile above for details
A fatal error has occurred. Check the logfile above for details
©2020安全亚搏在线软件公司|合法的