socket.error: [Errno 104] Connection reset by peer


Traceback (most recent call last):
  File "/home/veepsirtt/", line 53, in <module>
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/", line 248, in get
    self.execute(Command.GET, {'url': url})
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/", line 234, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/", line 401, in execute
    return self._request(command_info[0], url, body=data)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/", line 433, in _request
    resp = self._conn.getresponse()
  File "/usr/lib/python2.7/", line 1089, in getresponse
  File "/usr/lib/python2.7/", line 444, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/", line 400, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/lib/python2.7/", line 476, in readline
    data = self._sock.recv(self._rbufsize)
socket.error: [Errno 104] Connection reset by peer

Why driver.get(url) returns socket.error: [Errno 104] Connection reset by peer .

[edit by admin: formatting]

What code are you using to start Selenium? Is it similar to our sample code? If so, can we take a look at your code? We can see it from our admin interface, but we always ask for permission first.

My code with keys hidden. I am running on chromedriver but in Firebox returns [Errno 104] help me pls?.

#from upstox_api.api import upstox

from upstox_api.api import Upstox

from upstox_api.api import Session

from upstox_api.api import requests

from upstox_api.api import future

from pprint import pprint

#import schedule
import urlparse

from pyvirtualdisplay import Display

from selenium import webdriver

#Create a Session object with your api_key, redirect_uri and api_secret

upstok_api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

upstok_api_secret ="xxxxxxxxxxxxxxxxxxxxxxxxxxxx"


s = Session (upstok_api_key)


s.set_api_secret (upstok_api_secret)

url =s.get_login_url()

# Open URL in new browser window # opens in default browser

print ('url= %s' % url)

#from selenium import webdriver

# set the path for chromedriver.exe file
#driver = webdriver.Chrome("/upstok/chromedriver.exe")

with Display():
# we can now start Firefox and it will run inside the virtual display

 driver = webdriver.Firefox()

# put the rest of our selenium code in a try/finally

# to make sure we always clean up at the end


#print driver.title #this should print "Google"


# Navigate to new URL in new tab


user = driver.find_element_by_name("username")

password = driver.find_element_by_name("password")

year = driver.find_element_by_name("password2fa")









input = driver.find_element_by_id("allow")


#get current url

parsed = urlparse.urlparse(driver.current_url)


#Retrieve your access token

access_token = s.retrieve_access_token()


u = Upstox (upstok_api_key, access_token)

pprint ('Received access_token: %s' % access_token)

[edit by admin: formatting]

OK, it looks like you're trying to access Selenium after you've closed the display. The command

with Display():

...opens a display, and then runs the code inside the "with" block, then closes the display. This means that when Python gets to the line


...which is outside the "with" block, the display is closed. You should indent all of the selenium code (everything up to the driver.quit() so that it's contained inside the with block.