Exception AttributeError: "'NoneType' object has no attribute 'path'" in

wannabhappy picture wannabhappy · Jul 25, 2016 · Viewed 11.2k times · Source

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.

Answer

Pat picture Pat · Oct 26, 2016

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.