Forums

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

.

Traceback (most recent call last):
  File "/home/veepsirtt/vp.py", line 53, in <module>
    driver.get(url)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 248, in get
    self.execute(Command.GET, {'url': url})
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 234, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 401, in execute
    return self._request(command_info[0], url, body=data)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 433, in _request
    resp = self._conn.getresponse()
  File "/usr/lib/python2.7/httplib.py", line 1089, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 444, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 400, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/lib/python2.7/socket.py", 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?.

#!/user/bin/python2.7
.
#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"

redirect_uri='http://127.0.0.1/login'

s = Session (upstok_api_key)

s.set_redirect_uri(redirect_uri)

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")
#C:/python27/Scripts/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

#try:
#driver.get('http://www.google.com')

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


driver.get(url)

# Navigate to new URL in new tab

driver.implicitly_wait(2)

user = driver.find_element_by_name("username")

password = driver.find_element_by_name("password")

year = driver.find_element_by_name("password2fa")

user.clear()

user.send_keys("xxxxxxxxxxxxxxxxxxxxxx")

password.clear()

password.send_keys("xxxxxxxxxxxxxxxxxxxxxxxxx")

year.clear()

year.send_keys("xxxxxxxxxxxxxxxxxxxxxxxxx")

year.send_keys(u'\ue007')

driver.get(driver.current_url)

input = driver.find_element_by_id("allow")

input.send_keys(u'\ue007')

#get current url

parsed = urlparse.urlparse(driver.current_url)

s.set_code(urlparse.parse_qs(parsed.query)["code"])

#Retrieve your access token

access_token = s.retrieve_access_token()

driver.quit();

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

driver.get(url)

...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.