尝试使用附加到文件引发AttributeError异常

时间:2018-10-29 02:47:18

标签: robotframework

我正在尝试将存储在变量中的数据附加到文件中。成功创建文件,并将数据存储在变量中;但是,我继续收到AttiributeError:

AttributeError: 'NoneType' object has no attribute 'replace' 

这是我的结果

KEYWORD ${FileA} = OperatingSystem . Create File metrics/Live_RTT.txt, ${MT_Com_RTT_LB_Live_Topics}
00:00:05.233 KEYWORD Selenium2Library . Click Element ${BLANK_CANVAS}
00:00:05.129 KEYWORD Selenium2Library . Click Element //div[@title='${device1}']
00:00:05.063 KEYWORD Selenium2Library . Click Element //div[@title='${device2}']
00:00:00.045 KEYWORD ${MT_Com_RTT_LB_Live_Topics} = Selenium2Library . Get Text xpath=${REAL_TIME_TRENDING_TOPICS}
00:00:00.001 KEYWORD BuiltIn . Log ${MT_Com_RTT_LB_Live_Topics}
Documentation:  

Logs the given message with the given level.
Start / End / Elapsed:  20181028 21:37:34.971 / 20181028 21:37:34.972 / 00:00:00.001
21:37:34.971    INFO    Available Topics
Active Energy Delivered + Received
Active Energy Into the Load
Active Energy Out of the Load
Active Power
Active Power A  
00:00:00.001 KEYWORD OperatingSystem . Append To File ${FileA}, ${MT_Com_RTT_LB_Live_Topics}
Documentation:  

Appends the given content to the specified file.
Start / End / Elapsed:  20181028 21:37:34.972 / 20181028 21:37:34.973 / 00:00:00.001
21:37:34.973    FAIL    AttributeError: 'NoneType' object has no attribute 'replace'

1 个答案:

答案 0 :(得分:1)

查看库的源代码,最有可能在normalize_path()方法中引发了异常,该方法执行以下字符串替换:

    path = os.path.normpath(os.path.expanduser(path.replace('/', os.sep)))

,其中path是文件名-Append To File kw调用的第一个参数。异常表示其值为None(例如,未设置任何值),但应为某些字符串。

查看日志,您正在将此值设置为Create File的返回值-但该关键字根本不会返回一个,它只是创建您在其第一个参数中指定的文件。
因此,要解决此问题-只需自己设置${FileA}的值,将其传递给两个关键字,而不必重新分配Create File调用。