Exception AttributeError: “'NoneType' object has no attribute 'path'” in

孤街浪徒 提交于 2019-12-24 00:23:07

问题


I am debugging python code (python2.7.12) as my code works but I get NULL for all variables when streaming tweets into the database.

The error I got is:

Exception AttributeError: "'NoneType' object has no attribute 'path'" in <function _remove at 0x10068f140> ignored

I am assuming this error is from the code below:

def put_tweets_in_database(tweets):
    print "putting tweets in database"
    errors = 0
    count = 0

    for tweet in tweets:
        try:
            commit_tweet_to_database(tweet, count, len(tweets))
            count += 1  
        except Exception as e:
            print e
            session.rollback()
            errors += 1
    print 'there were {} errors'.format(errors)

I don't think the function commit_tweet_to_database() is wrong...

Do you have any idea...? I would appreciate any help!

Thank you.


回答1:


Exception AttributeError: "'NoneType' object has no attribute 'path'" in <function _remove at 0x10068f140> ignored

This tells that in function _remove an attribute path was tried to be accessed on a NoneType object. NoneType objects have no attributes. So may be you need to look at _remove function and start debugging from there.




回答2:


I am also dealing with this error. I tried using the browser.close() method, and while it does stop the - 'NoneType' object has no attribute 'path' - from being displayed, I am left with a bunch of open firefox browser instances.

The .close() method closes chrome, and it doesn't throw the NoneType error in firefox, but it leaves firefox open. The .quit() method closes both browsers, but it throws the error for firefox.

I am using django's StaticLiveServerTestCase class for my code.

I wrote a little debugger loop to test things out. Just uncomment and comment out the .quit() and .close() statements.

class BaseTestCase(StaticLiveServerTestCase):

    @classmethod
    def setUp(self):

        self.firefox = webdriver.Firefox()
        self.chrome = webdriver.Chrome()
        self.browsers = [self.firefox, self.chrome]

    @classmethod
    def tearDown(self):

        for browser in self.browsers:
            if browser == self.firefox:
                print('firefox')
                browser.close()
                # browser.quit()
            elif browser == self.chrome:
                print('chrome')
                browser.close()
                # browser.quit()

I still don't know the answer, but I think this is a step in the right direction.




回答3:


It sounds as-though your "try" clause is failing, causing the exception to be printed? I'd likely add more debugging to the Exception catch, such as printing out the arguments to commit_tweet_to_database, just to make sure you're passing viable parameters.




回答4:


Try removing this line of code:

import pdb;pdb.set_trace()

Guess the script already called pdb.set_trace() and you are trying to override it. This might be a reason for the issue.




回答5:


I have the same error and here is my case:

browser = webdriver.Firefox()

browser.get('http://www.google.com')

print browser.title

  • this following will give me error message: 'NoneType' object has no attribute 'path'

browser.quit()

  • this following will not give error

browser.close()

So the issue is that you have use the wrong method for your object!



来源:https://stackoverflow.com/questions/38574821/exception-attributeerror-nonetype-object-has-no-attribute-path-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!