Skip to content Skip to sidebar Skip to footer

Attributeerror: 'nonetype' Object Has No Attribute 'close'

I am new to python js I am trying to run a project that are available on github but when I am trying to run it gives following error Traceback (most recent call last): File 'ma

Solution 1:

My guess would be that both attempts to create a driver - PhantomJS and FireFox - fail, meaning that driver is still None when you reach the finally block. You could confirm this by adding an explicit check:

    finally:
        if driver:
            driver.close()
        else:
            print"Could not create driver"

As to why driver creation would be failing, the most likely explanation is an installation problem. You can test this by running a trivial example in your Python environment:

>>>from selenium.webdriver import Firefox>>>d = Firefox()>>>d.get('http://stackoverflow.com')

If this doesn't open Firefox and navigate to the front page of Stack Overflow, check the Selenium documentation for your OS.

Solution 2:

driver isn't initialised if both the creation of PhantomJS and Firefox fail.

Add a check before closing:

if driver:
    driver.close()

Solution 3:

if both the try ...except clause failed in crawler_machine, the global value of driver will be None.

Post a Comment for "Attributeerror: 'nonetype' Object Has No Attribute 'close'"