-1
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()

这是我的错误和代码。我对为什么会收到此错误感到困惑。有人可以帮帮我吗?越来越令人沮丧。

4

2 回答 2

4

你忘了检查你的正则表达式是否真的匹配任何东西。如果不是,则相应方法的返回值将是None.

于 2012-11-07T07:04:06.060 回答
0

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

于 2017-08-25T08:57:42.873 回答