Python 属性错误:';非类型';对象没有属性';集团';

Python 属性错误:';非类型';对象没有属性';集团';,python,raspberry-pi,Python,Raspberry Pi,请提供帮助,因为我正在尝试使用树莓pi pir传感器将pir传感器(1或0)收集的数据传输到web服务 我犯了这个错误 Traceback (most recent call last): File "pir_5.py", line 54, in <module> moveHold = float(matches.group(1)) AttributeError: 'NoneType' object has no attribute 'group' 在你写的时候 mat

请提供帮助,因为我正在尝试使用树莓pi pir传感器将pir传感器(1或0)收集的数据传输到web服务 我犯了这个错误

Traceback (most recent call last):
  File "pir_5.py", line 54, in <module>
    moveHold = float(matches.group(1))
AttributeError: 'NoneType' object has no attribute 'group'

在你写的时候

matches.group(...)
匹配项为
None
。您的正则表达式搜索似乎未能找到匹配项。如果正则表达式搜索可能失败,则需要显式处理该场景:

if matches is None:
    ....
或者,可能真正的问题是执行搜索的代码是错误的


与其让我精确地告诉您如何解决问题,不如让您了解如何解释此特定错误消息

在你写的地方

matches.group(...)
匹配项为
None
。您的正则表达式搜索似乎未能找到匹配项。如果正则表达式搜索可能失败,则需要显式处理该场景:

if matches is None:
    ....
或者,可能真正的问题是执行搜索的代码是错误的


与其让我精确地告诉您如何解决问题,不如让您了解如何解释此特定错误消息

那么显然,
输出
不包含预期的字符串。(当它是通过调用echo 18生成的时,它应该如何处理呢?)

返回
None
,它没有的
.group()

  moveHold = float(matches.group(1))
这样你就得到了所说的例外

你应该把它改成

    matches = re.search("Current_State==1 and Previous_State==0", output)
    if matches:
        moveHold = float(matches.group(1))
        resultm = client.service.retrieveMove(moveHold)
        ...
    else:
        # code for if it didn't match

显然,
输出
不包含预期的字符串。(当它是通过调用echo 18生成的时,它应该如何处理呢?)

返回
None
,它没有的
.group()

  moveHold = float(matches.group(1))
这样你就得到了所说的例外

你应该把它改成

    matches = re.search("Current_State==1 and Previous_State==0", output)
    if matches:
        moveHold = float(matches.group(1))
        resultm = client.service.retrieveMove(moveHold)
        ...
    else:
        # code for if it didn't match