Forums

Browser does not opens page (error: The proxy server is refusing connection)

Hi I am trying to open web page using web driver and virtual display but my page does not open screenshot of display says "Proxy Server is refusing connection" it works for yahoo, google but not workin for "www.routehappy.com" and other similar sites

here is my code

import selenium as sl
from selenium import webdriver
from bs4 import BeautifulSoup as bs
import urllib2
import csv
import os
import re
import time
import datetime
from selenium.webdriver.common.keys import Keys
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(800, 600))
display.start()

browser = webdriver.Firefox()
browser.get('https://www.routehappy.com')
time.sleep(20)
browser.save_screenshot('routehappy.png')
browser.quit()
display.stop()

screenshot of Virtualdisplay enter image description here

Hi Hitendra, free users are restricted to a whitelist of sites.

this is my code:

!/usr/local/bin/python3.4

from selenium import webdriver import time from pyvirtualdisplay import Display display = Display(visible=0, size=(800, 600)) display.start() time.sleep(3) driver = webdriver.Firefox() driver.get('https://github.com/') time.sleep(5) driver.quit() display.stop() the site is om the whitelist , but no window opens , can you tell me why?

pyvirtualdisplay creates a virtual display. It's not going to open a window.

did u make it work? I could get selenium to work on pythonanywhere. some weird page error pops instead of the one i need. this is my code.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from pyvirtualdisplay import Display

def function():
    display = Display(visible=0, size=(800, 600))
    display.start()
    browser = webdriver.Firefox()
    browser.get("https://www.mypage.com/")
    browser.implicitly_wait(30)
    print (browser.page_source)

    try:
        print is_element_present(browser,By.ID, "signInButton")
        browser.implicitly_wait(30)
        browser.save_screenshot('screenie.png')
        time.sleep(10)
    except Exception, e:
        print e
    return browser,display


def is_element_present(driver,how, what):
    try: driver.find_element(by=how, value=what)
    except NoSuchElementException as e: return False
    return True


def close(browser,display):
    try:
        browser.quit()
    except Exception, e:
        print "browser.quit.error:  %s"%str(e)
    try:
        display.stop()
    except Exception, e:
        print "browser.quit.error:  %s"%str(e)

if __name__ == '__main__':
    try:
        b,d = function()
        close(b,d)
    except Exception, e:
        print e

[edited by admin: formatting]

and this would be the source page a get:

<!DOCTYPE html [ <!ENTITY % htmlDTD PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> %htmlDTD; <!ENTITY % netErrorDTD SYSTEM "chrome://global/locale/netError.dtd"> %netErrorDTD;

<!ENTITY loadError.label "Problem loading page"> <!ENTITY retry.label "Try Again">

<!-- Specific error messages -->

<!ENTITY connectionFailure.title "Unable to connect"> <!ENTITY connectionFailure.longDesc "&sharedLongDesc;">

<!ENTITY deniedPortAccess.title "This address is restricted"> <!ENTITY deniedPortAccess.longDesc "">

<!ENTITY dnsNotFound.title "Server not found"> <!ENTITY dnsNotFound.longDesc " <ul> <li>Check the address for typing errors such as <strong>ww</strong>.example.com instead of <strong>www</strong>.example.com</li> <li>If you are unable to load any pages, check your computer's network connection.</li> <li>If your computer or network is protected by a firewall or proxy, make sure that &brandShortName; is permitted to access the Web.</li> </ul> ">

<!ENTITY fileNotFound.title "File not found"> <!ENTITY fileNotFound.longDesc " <ul> <li>Check the file name for capitalization or other typing errors.</li> <li>Check to see if the file was moved, renamed or deleted.</li> </ul> ">

<!ENTITY generic.title "Oops."> <!ENTITY generic.longDesc " <p>&brandShortName; can't load this page for some reason.</p> ">

<!ENTITY malformedURI.title "The address isn't valid"> <!ENTITY malformedURI.longDesc " <ul> <li>Web addresses are usually written like <strong>http://www.example.com/</strong></li> <li>Make sure that you're using forward slashes (i.e. <strong>/</strong>).</li> </ul> ">

<!ENTITY netInterrupt.title "The connection was interrupted"> <!ENTITY netInterrupt.longDesc "&sharedLongDesc;">

<!ENTITY notCached.title "Document Expired"> <!ENTITY notCached.longDesc "<p>The requested document is not available in &brandShortName;'s cache.</p><ul><li>As a security precaution, &brandShortName; does not automatically re-request sensitive documents.</li><li>Click Try Again to re-request the document from the website.</li></ul>">

<!ENTITY netOffline.title "Offline mode"> <!ENTITY netOffline.longDesc2 " <ul> <li>Press "Try Again" to switch to online mode and reload the page.</li> </ul> ">

<!ENTITY contentEncodingError.title "Content Encoding Error"> <!ENTITY contentEncodingError.longDesc " <ul> <li>Please contact the website owners to inform them of this problem.</li> </ul> ">

<!ENTITY unsafeContentType.title "Unsafe File Type"> <!ENTITY unsafeContentType.longDesc " <ul> <li>Please contact the website owners to inform them of this problem.</li> </ul> ">

<!ENTITY netReset.title "The connection was reset"> <!ENTITY netReset.longDesc "&sharedLongDesc;">

<!ENTITY netTimeout.title "The connection has timed out"> <!ENTITY netTimeout.longDesc "&sharedLongDesc;">

<!ENTITY protocolNotFound.title "The address wasn't understood"> <!ENTITY protocolNotFound.longDesc " <ul> <li>You might need to install other software to open this address.</li> </ul> ">

<!ENTITY proxyConnectFailure.title "The proxy server is refusing connections"> <!ENTITY proxyConnectFailure.longDesc ">

<ul> <li>Check the proxy settings to make sure that they are correct.</li> <li>Contact your network administrator to make sure the proxy server is working.</li> </ul> ">

<!ENTITY proxyResolveFailure.title "Unable to find the proxy server"> <!ENTITY proxyResolveFailure.longDesc " <ul> <li>Check the proxy settings to make sure that they are correct.</li> <li>Check to make sure your computer has a working network connection.</li> <li>If your computer or network is protected by a firewall or proxy, make sure that &brandShortName; is permitted to access the Web.</li> </ul> ">

<!ENTITY redirectLoop.title "The page isn't redirecting properly"> <!ENTITY redirectLoop.longDesc " <ul> <li>This problem can sometimes be caused by disabling or refusing to accept cookies.</li> </ul> ">

<!ENTITY unknownSocketType.title "Unexpected response from server"> <!ENTITY unknownSocketType.longDesc " <ul> <li>Check to make sure your system has the Personal Security Manager installed.</li> <li>This might be due to a non-standard configuration on the server.</li> </ul> ">

<!ENTITY nssFailure2.title "Secure Connection Failed"> <!ENTITY nssFailure2.longDesc " <ul> <li>The page you are trying to view cannot be shown because the authenticity of the received data could not be verified.</li> <li>Please contact the website owners to inform them of this problem. Alternatively, use the command found in the help menu to report this broken site.</li> </ul> ">

<!ENTITY nssBadCert.title "Secure Connection Failed"> <!ENTITY nssBadCert.longDesc2 " <ul> <li>This could be a problem with the server's configuration, or it could be someone trying to impersonate the server.</li> <li>If you have connected to this server successfully in the past, the error may be temporary, and you can try again later.</li> </ul> ">

<!ENTITY sharedLongDesc " <ul> <li>The site could be temporarily unavailable or too busy. Try again in a few moments.</li> <li>If you are unable to load any pages, check your computer's network connection.</li> <li>If your computer or network is protected by a firewall or proxy, make sure that &brandShortName; is permitted to access the Web.</li> </ul> ">

<!ENTITY malwareBlocked.title "Suspected Attack Site!"> <!ENTITY malwareBlocked.longDesc " <p>Attack sites try to install programs that steal private information, use your computer to attack others, or damage your system.</p> <p>Website owners who believe their site has been reported as an attack site in error may <a href='http://www.stopbadware.org/home/reviewinfo' >request a review</a>.</p> ">

<!ENTITY phishingBlocked.title "Suspected Web Forgery!"> <!ENTITY phishingBlocked.longDesc " <p>Entering any personal information on this page may result in identity theft or other fraud.</p> <p>These types of web forgeries are used in scams known as phishing attacks, in which fraudulent web pages and emails are used to imitate sources you may trust.</p> ">

<!ENTITY cspFrameAncestorBlocked.title "Blocked by Content Security Policy"> <!ENTITY cspFrameAncestorBlocked.longDesc "<p>&brandShortName; prevented this page from loading in this way because the page has a content security policy that disallows it.</p>">

<!ENTITY corruptedContentError.title "Corrupted Content Error"> <!ENTITY corruptedContentError.longDesc "<p>The page you are trying to view cannot be shown because an error in the data transmission was detected.</p><ul><li>Please contact the website owners to inform them of this problem.</li></ul>">

<!ENTITY securityOverride.linkText "Or you can add an exception…"> <!ENTITY securityOverride.getMeOutOfHereButton "Get me out of here!"> <!ENTITY securityOverride.exceptionButtonLabel "Add Exception…">

<!-- LOCALIZATION NOTE (securityOverride.warningContent) - Do not translate the contents of the <button> tags. It uses strings already defined above. The button is included here (instead of netError.xhtml) because it exposes functionality specific to firefox. -->

<!ENTITY securityOverride.warningContent " <p>You should not add an exception if you are using an internet connection that you do not trust completely or if you are not used to seeing a warning for this server.</p>

<button id='getMeOutOfHereButton'>&securityOverride.getMeOutOfHereButton;</button> <button id='exceptionDialogButton'>&securityOverride.exceptionButtonLabel;</button> ">

<!ENTITY remoteXUL.title "Remote XUL"> <!ENTITY remoteXUL.longDesc "<p><ul><li>Please contact the website owners to inform them of this problem.</li></ul></p>">

<!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd"> %globalDTD; ]>

does accessing any other website work as expected? maybe the website you are trying to access it blocking you?