How to fix "Cannot connect to server" exception? - python-3.x

I was setting up chromedriver with selenium, using the test script provided on the chromdriver website. Everything worked fine, until I switched to a different WiFi network. Now I'm getting an error message when running my script.
I have searched the web for solutions, and I've tried the following things:
Made sure the chromedriver version matches my chrome version.
Try to whitelist the ip-address
I checked for 127.0.0.1 localhost in /etc/hosts
The test code I'm running (/path/to/my/chromedriver is correct):
import time
from selenium import webdriver
driver = webdriver.Chrome("/path/to/my/chromedriver") # Optional argument, if not specified will search path.
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
I'm expecting the program to run fine, and the browser should pop up. However, the browser is not popping up and I'm getting the following error message:
File "test.py", line 4, in
driver = webdriver.Chrome("/path/to/my/chromedriver") # Optional argument, if not specified will search path.
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in init
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 104, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service /path/to/my/chromedriver
When running the chromedriver in the terminal I'm getting the following message (and the browser is also not popping up as supposed to):
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
EDIT: I have the same problem with the geckodriver for firefox, so it is not specific for Chrome.

Related

Can't run selenium firefox browser

I have a problem with run selenium firefox browser.
It started after last update OS.
I use ubuntu 22.04
When I try to run test i catch this exception
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 127
I try google it, but didn't find information.
Also I have the such information in firefox log file/snap/firefox/current/firefox.launcher: 46: exec: /snap/pycharm-community/302/usr/lib/firefox/firefox: not found
Try this:
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
firefox_options = webdriver.FirefoxOptions()
# Your location binary file firefox
firefox_options.binary_location = "/usr/bin/firefox"
# location geckodriver
s = Service("config/geckodriver")
driver = webdriver.Firefox(options=firefox_options, service=s)

pysmb not working on linux ubuntu server 22.04 LTS

I have a telegram bot and there I implemented support for receiving files from a file server, in my case smb. The problem is that on the local everything works fine! You also need to keep in mind that I have Ubuntu 20.04 on my local. This is the only thing I haven't been able to check. And I checked the following points.
on the server, the python version was 3.10.4, on the local 3.9. Then i installed the latest version of python and the project works great!
and on the server, when trying to make a connection to SMB, there was an error:
File "bot/venv/lib/python3.10/site-packages/smb/utils/md4.py", line 251, in int_array2str
nstr = nstr + str(chr(i))
TypeError: 'U32' object cannot be interpreted as an integer
Then I found this problem on the Python discuss and tried to do the same. This error disappeared but another, more direct one came up. Now it's just AssertionError and points to the string with the connection attempt.
This is my code with connection:
conn = SMBConnection(
SMB_LOGIN, SMB_PASSWORD,
LOCAL_NAME, SMB_REMOTE_NAME, use_ntlm_v2=True
)
assert conn.connect(SMB_IP_ADDRESS, 139)
There doesn't seem to be anything remarkable here.
I also tried to change ports, put 445/135/137.
445:
ConnectionResetError: [Errno 104] Connection reset by peer
135 and 137:
timeout expired
A simple connection via the smbclient from the terminal also works.
I don't understand what exactly is the problem. The only thing left for me to check is to change the version of Linux. But I also do not believe that after that it will start working

How to execute Chrome-webdriver in Azure Cloud Service?

You are about to run the chrome-webdriver on an azure cloud service.
However, the following error occurs.
chrome_webdriver sample code
from selenium import webdriver
driver = webdriver.Chrome('/.chromedriver.exe')
url = "https://www.instagram.com/"
driver.get(url)
If you look at the picture, I put the chrome-driver file in the same directory as .ipynb
The path was set to './chromedriver.exe', but an error occurred.
Other attempted methods
1. driver = webdriver.Chrome(r"\chromedriver.exe")
2. driver = webdriver.Chrome("\\chromedriver.exe")
3. driver = webdriver.Chrome("/chromedriver.exe")
-> I tried a different method, but an error occurred.
how to chrome-webdriver excute in azure cloud service?
Vova Bilyachat Update posts for comments
1. driver = webdriver.Chrome('./Users/admin/chromedriver.exe')
-> Message: 'chromedriver.exe' executable needs to be in PATH.
2. driver = webdriver.Chrome('./chromedriver.exe')
-> OSError: [Errno 8] Exec format error: './chromedriver.exe'
update post2
I think your error is that you set path "/chromedriver.exe" which is looking for file in root folder, change it to "./chromedriver.exe" where "./" means start from folder you execute script
Also you must be sure that you deployed right driver for right Operating System
And since its linux use
driver = webdriver.Chrome('/.chromedriver')

Selenium, VBA - ERR_PROXY_CONNECTION_FAILED with chromedriver update 86.0.4240.111

It's been working fine until the latest chrome update. As usual I downloaded the latest Chromedriver update to complement the newest release of chrome but now I'm getting the following error once it tries to open a page.
I'm using a proxy so initially I launch chrome without the proxy to ensure there is no connection without proxy, then I launch Putty and connect the proxy server. This has all worked seamlessly until this latest update.
I've included a section of my code below:
Public Driver As New WebDriver
Set Driver = New ChromeDriver
Driver.SetProfile Sheets("Settings").Range("B52").Value
Driver.AddArgument ("--proxy-server=socks5://localhost:1194")
'Set download directory
Driver.SetPreference "download.default_directory", Sheets("Settings").Range("B44").Value
Driver.Get "https://www.google.co.uk/", timeout:=none ', False
If Driver.FindElementsByXPath("//*[contains(text(),'The proxy server is refusing connections')]").Count Or Driver.FindElementsByXPath("//*[contains(text(),'There is something wrong with the proxy server')]").Count Then
Open_Putty_and_Connect_to_Host_Network
end if
Error occurs at driver.get
Full Error Message:
Run_time error '13':
UnknownError
unknown error: net::ERR_PROXY_CONNECTION_FAILED
(Session info: chrome=86.0.4240.111)
(Driver info: chromedriver=86.0.4240.22)
(398b0743353ff36fb1b82468f63a3a93b4e2e89e-refs/branch-heads/424
NT 10.0.18362 x86_64)
I've been looking online and what I can see I need to pass an argument to the chrome driver but I'm not sure how to or what I need to pass to it.
The code will run beyond this point normally and connect to the proxy and perform it's standard function but I can't understand why this error is occurring or how to fix it. Any help would be greatly appreciated!

get chrome app console logs in chrome os debug log

I've got a chrome app with several isolated layers (webviews, iframes), all those layers are logging some debugging stuff to console with console.log().
I managed to get all console logs inside a chrome debug log when launching chrome on mac os with --enable-logging --v=1 flags.
The problem is I can't get all the console.logs when running the app in chrome os. For chrome os debugging I wrote the following into /etc/chrome_dev.conf file:
CHROME_LOG_FILE=/tmp/chrome_debug.log
--enable-logging --v=1
So I expect pretty much the same logs as I get when running chrome app on mac os, but I do not see any console.logs in /tmp/chrome_debug.log.
Would appreciate any advice how to get my app console.logs in chrome debug log on chrome os
Please read the comments in the /etc/chrome_dev.conf file, particularly this one at the top:
# This file may be modified to make local changes to the environment and command
# line that session_manager uses to run Chrome. It contains one directive per
# line, with the following forms available:
That means your --enable-logging --v=1 is incorrect because you put two options on one line instead of one option per line.

Resources