首页 > 解决方案 > 来自代码编辑器的 common.py 文件的断言错误

问题描述

请注意:我是 Python 的初学者)当我尝试输入我的 bssid 时,它给了我一个断言错误,它引用了另一个名为 common.py 的代码文件的一部分,我认为它是我的代码编辑器 (thonny) 附带的。我将如何解决这个问题?

import os
import time

opsys = input("Are you using MacOS or Windows? ")

if (opsys.lower() == "windows"): 
    print("\n Alrighty, let me just open u your command prompt for you.") 
    time.sleep(0.5)
    os.system("start /B start cmd.exe @cmd /k netsh wlan show interfaces")
    time.sleep(0.25)
    bssid = input("\nNow paste in the set of numbers labelled BSSID: ")
    print("Thanks")

这是断言错误从 common.py 引用的语句:

def parse_message(msg_string: str) -> Record:
    # DataFrames may have nan
    # pylint: disable=unused-variable
    nan = float("nan")  # @UnusedVariable
    assert msg_string[0] == MESSAGE_MARKER
    return eval(msg_string[1:].encode("ASCII").decode("UTF-7"))

这是整个回溯错误:

Traceback (most recent call last):
  File "C:\Users\tjmon\Documents\Honors Comp Sci\Other Programs\Lab3.py", line 60, in <module>
    bssid = input("\nNow paste in the set of numbers labelled BSSID: ")
  File "C:\Users\tjmon\AppData\Local\Programs\Thonny\lib\site-packages\thonny\common.py", line 220, in parse_message
    assert msg_string[0] == MESSAGE_MARKER
AssertionError

标签: pythonthonny

解决方案


所以在common.py 中它被引用为MESSAGE_MARKER = "\x02",这意味着类似于“文本开始”

Oct  Dec Char  Hex  Key     Comments
\000   0  NUL  \x00  ^@ \0 (Null byte)
\001   1  SOH  \x01  ^A    (Start of heading)
\002   2  STX  \x02  ^B    (Start of text)

也许这只是 thonny 中的一个错误 - 您是否尝试过没有它的程序?


推荐阅读