AttributeError:“NoneType”对象没有属性“start”

2024-10-01 15:36:33 发布

您现在位置:Python中文网/ 问答频道 /正文

Traceback (most recent call last):
  File "NinjaWarzBot.py", line 354, in <module>
    stats = comm.init()
  File "C:\Users\Administrator\Desktop\ninja warz bot\NinjaWarzLib.py", line 33,
 in init
    mf.seek(m.start()+len(cookieKey)) # reset file cursor
AttributeError: 'NoneType' object has no attribute 'start'
Press any key to continue . . .

def init():
    cookieDBFilename = os.path.join(os.environ['USERPROFILE'], "AppData/Local/Google/Chrome/User Data/Default/Cookies")
    cookieKey = "kongregate.ninjawarz.brokenbulbstudios.comPHPSESSID"
    f = open(cookieDBFilename, 'r+b')
    mf = mmap.mmap(f.fileno(), 0)
    mf.seek(0) # reset file cursor
    m = re.search(cookieKey+'\w+', mf)

    mf.seek(m.start()+len(cookieKey)) # reset file cursor
    global _sessionId
    _sessionId = mf.read(m.end() - m.start() -len(cookieKey))
    mf.close()
    f.close()

    return getMyStats()

这是我的错误和代码。我不明白为什么我会犯这个错误。有人能帮帮我吗?这让人沮丧。在


Tags: inpyleninitoslineseekstart
2条回答

你可以打印搜索(cookieKey+'\w+',mf)在执行.start()之前,这样您就可以查看是否确实搜索了某些内容。 但是,如果你的文本中有匹配的字符串,搜索只返回一个对象

你忘了检查你的正则表达式是否与任何内容匹配。如果不是,那么从适当的方法返回的值将是None。在

相关问题 更多 >

    热门问题