Search code examples
pythonselenium-webdriverbioinformatics

'DisallowedHost' Exception using Selenium to access website


I am attempting to access a website using selenium for the purposes of automating data analysis. The site is http://dbtoolkit.cistrome.org/ . I have no issues accessing the site normally, but when attempting to utilize selenium I'm having issues. Here's my code below:

def setup_driver():

    #Establish settings
    options = Options()

    options.add_argument('--ignore-ssl-errors=yes') #ignore insecure warning
    options.add_argument('--ignore-certificate-errors')

    #establish driver
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),
                              options=options)

    return driver

driver = setup_driver()
driver.get('http://dbtoolkit.cistrome.org')

Solution

  • I had to remove the previous post because i could not share the new code there in comment.DisallowedHost error, it's likely that the website's server is configured to only accept requests from specific hosts or there are restriction issue.

    Some website may perform differently when run on non-headless mode.you may try adding headless and check the screenshot to confirm whether you opened the website successfully or not.Below is the code.

    options = Options()
    options.add_argument('--ignore-ssl-errors=yes')  # Ignore insecure warning
    options.add_argument('--ignore-certificate-errors')
    ## add headless
    options.add_argument("--headless") 
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
    driver.get('http://dbtoolkit.cistrome.org')
    
    ## take screenshot to check if the driver successfully opened the website
    driver.save_screenshot("screenshot.png")
    

    or may try adding agent header in driver option