ConnectionResetError: [WinError 10054] When using Selenium Chrome - python-3.x

Hello i have a simple problem that has suddenly developed on my code, until yesterday it was working correctly, this means it opened a web page and entered login details (is a test for a bigger app), however now whenever it tries to connect to the login page i get a timeout error. I have updated Selenium and Chrome Web Driver to the latest and it is still failing to connect, this is my code:
#importing libraries, selenium is the base of the script, time to add pauses when appropiate or necessary and select and request will stay until i determine that they are not necessary for the final script.
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time
import requests
#defining browser to use the webdriver with chrome, and navigating to Makor.
browser = webdriver.Chrome()
browser.get('http://mrmprod/Login.aspx')
And this is the complete error code:
Traceback (most recent call last):
File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\Scripts\Input
test.py", line 7, in
browser = webdriver.Chrome()
File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py",
line 69, in init
desired_capabilities=desired_capabilities)
File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 92, in init
self.start_session(desired_capabilities, browser_profile)
File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 234, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 407, in execute
return self._request(command_info[0], url, body=data)
File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 439, in _request
resp = self._conn.getresponse()
File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\http\client.py",
line 1197, in getresponse
response.begin()
File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\http\client.py",
line 297, in begin
version, status, reason = self._read_status()
File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\http\client.py",
line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\socket.py",
line 575, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
I asked the network administrator and he has told me that there hasn't being any change on the network settings since i originally got the code working.

If you have reviewed the aforementioned then do the following steps:
You have to include inside the parenthesis the chromedriver path.
Check the code below:
CODE SAMPLE FOR WINDOWS OS
browser = webdriver.Chrome('C:\\User\\YOUR_USERS_NAME\\YOUR_PATH\\chromedriver.exe')
CODE SAMPLE FOR LINUX OS
browser = webdriver.Chrome('usr\\bin\\YOUR_PATH\\chromedriver')

Related

Two errors when trying to open firefox using selenium (Python); System cannot find the file specified; Geckodriver executable needs to be in PATH

import time
from selenium import webdriver
path = input("enter filepath: ")
driver = webdriver.Firefox(path)
driver.get("htpps://google.com")
This is the part of my code seemingly causing the error, I have been able to find any answers online. The code used to work when using r"c:\users\ellio\desktop\main" however this has since stopped working too, only without the top error. I have added the folder containg geckodriver to path and added the geckodriver exe to the same file as my code, but nothing seems to work.
Thanks in advance for any help.
Here are the errors
Traceback (most recent call last):
File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\ellio\Desktop\main\app.py", line 18, in <module>
driver = webdriver.Firefox(path)
File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
self.service.start()
File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
give a specific path of your driver
from selenium import webdriver
driver = webdriver.Chrome('D:\\chrome\\chromedriver.exe') #give location of driver you download
driver.get('http://www.google.com/');
time.sleep(5)
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5)
driver.quit()

getting "selenium.common.exceptions.SessionNotCreatedExceptionSelenium" error using InstaPy

[SETUP:
Windows 10 x64
PyCharm 2019.3.3 (Community Edition)]
I'm trying to create a simple Insta bot with InstaPy but I keep running into the same error
CODE:
from instapy import InstaPy
InstaPy(username='username', password='password').login()
I keep getting the following error:
Traceback (most recent call last):
File "C:/Users/Niku/PycharmProjects/InstaBot/InstaBot.py", line 6, in <module>
InstaPy(username='Rubixmusicprod', password='Niku2020').login()
File "C:\Users\Niku\PycharmProjects\InstaBot\venv\lib\site-packages\instapy\instapy.py", line 309, in __init__
self.browser, err_msg = set_selenium_local_session(
File "C:\Users\Niku\PycharmProjects\InstaBot\venv\lib\site-packages\instapy\browser.py", line 111, in set_selenium_local_session
browser = webdriver.Firefox(
File "C:\Users\Niku\PycharmProjects\InstaBot\venv\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "C:\Users\Niku\PycharmProjects\InstaBot\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\Niku\PycharmProjects\InstaBot\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Niku\PycharmProjects\InstaBot\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Niku\PycharmProjects\InstaBot\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
I've tried upgrading selenium, along with Geckodriver and related drivers.
It was a mission just to get InstaPy installed!
I may just have to go the browser automation way instead here.
Any help would be greatly appreciated!!
You must use Selenium with Geckodrive in Firefox
session = InstaPy(username=INSTAGRAM_LOGIN,
password=INSTAGRAM_PASSWORD,
geckodriver_path='geckodriver.exe')

Xvfb Selenium headless Chrome on Linux in Python

I'm trying to run chrome headless with selenium in Python.
I tried xvfb-run -a python3 message.py
And i get this error:
Traceback (most recent call last):
File "message.py", line 388, in <module>
initialize()
File "message.py", line 54, in initialize
driver = webdriver.Chrome(chrome_options = chrome_options)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.33.506178 (69ae10f91723897591ef1a3b465aa5d35011eb5e),platform=Linux 3.13.0-96-generic x86)
And initialize():
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--verbose")
chrome_options.add_argument("--log-path=chrome.log")
chrome_options.add_argument("window-size=1200x600")
chrome_options.add_argument("user-data-dir=\\")
driver = webdriver.Chrome(chrome_options = chrome_options)
driver.get('http://google.com')
I'm using Python 3.5 and chromedriver 2.33.506178 for Linux32 (Ubuntu as Server without Desktop)
I tested the same code on my other pc with linux mint, all works fine.
Hope you can help me :)
After checking my actual rights of writing/reading/executing I found my mistake. chromedriver weren't able to load while trying to execute with root rights.
After I changed chromedrivers permission all works fine now.

Error while open browser from selenium

my script
from selenium import webdriver
o = webdriver.Firefox()
and i get this problem
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 142, in __init__
self.service.start()
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python3.5/subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1283, in _execute_child
raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error
i searched on it and i found this
OSError: [Errno 8] Exec format error selenium
i get chromedriver and put it in '/usr/local/bin/'
like supposed,
it doesn't help
and also did the same thing with geckodriver
Trouble setting up selenium with python3(linux)
nothing work same error
and i try this shot
#!usr/bin/python
#!/usr/bin/env bash
from selenium import webdriver
web = webdriver.Firefox(executable_path="/usr/local/bin/chromedriver")
it give me that error :
Traceback (most recent call last):
File "/root/Desktop/test.py", line 5, in <module>
web = webdriver.Firefox(executable_path="/usr/local/bin/chromedriver")
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 142, in __init__
self.service.start()
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 96, in start
self.assert_process_still_running()
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/local/bin/chromedriver unexpectedly exited. Status code was: 1
Note :
operation system is kali linux
SMP Debian 4.9.18-1kali1 version,
firefox and selenium is up to date
driver should be updated one & did u try webdriver.Firefox(driver_path) ?
Uninstall instance of webdriver dependency and install the correct one which corresponds to your OS and browser version.Also when you give path of chrome ,it should end with chrome.exe and not chrome.

urllib.urlopen() gives socket error: Name or service not known on python2.7

I am just starting to use and learn Python, so this may seem vary naive to ask.
On my Linux system if i try to get a webpage using urllib.urlopen() I get an error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/urllib.py", line 86, in urlopen
return opener.open(url)
File "/usr/lib/python2.7/urllib.py", line 207, in open
return getattr(self, name)(url)
File "/usr/lib/python2.7/urllib.py", line 344, in open_http
h.endheaders(data)
File "/usr/lib/python2.7/httplib.py", line 954, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 814, in _send_output
self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 776, in send
self.connect()
File "/usr/lib/python2.7/httplib.py", line 757, in connect
self.timeout, self.source_address)
File "/usr/lib/python2.7/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
IOError: [Errno socket error] [Errno -2] Name or service not known
>>>
If I try to do the same in the Python 2.7 installed in my Windows 7 system, it works fine.
Since i am a novice, its difficult for me to diagnose the problem. I tried to research it but still haven't got any answers.
So my questions are:
What is different in the windows system that urlopen() works there but not on Linux.
What needs to be done to ensure that urlopen() works on the Linux system. Its necessary for me that it works since the the program I am developing has some bash command calls and the program depends extensively on the proper working of urllib.

Resources