pycharm-selenium-python: Unable to start chromedriver service - [WinError 193] %1 is not a valid Win32 application - selenium

This question is not a duplicate of
error using selenium chromedriver on windows 7 64 bit as I have tried all solutions mentioned there.
In directory env\lib\site-packages\selenium\webdriver\common\service.py, considering the following code in function start
cmd = [self.path]
cmd.extend(self.command_line_args())
self.process = subprocess.Popen(cmd, env=self.env,
close_fds=platform.system() != 'Windows',
stdout=self.log_file, stderr=self.log_file)
The value for cmd is: <class 'list'>: ['chromedriver', '--port=58808']
Within ../AppData/Local/Programs/Python/Python35/Lib/subprocess.py function __init__
self._execute_child(args, executable, preexec_fn, close_fds,
pass_fds, cwd, env,
startupinfo, creationflags, shell,
p2cread, p2cwrite,
c2pread, c2pwrite,
errread, errwrite,
restore_signals, start_new_session)
args is the only argument passed with value <class 'list'>: ['chromedriver', '--port=58999']
But it raises an exception: [WinError 193] %1 is not a valid Win32 application
This prevents starting of the chromedriver service.
So I changed the args to absolute_path_to_chrome_driver\\chromedriver:
self._execute_child(args, 'absolute_path_to_chrome_driver\\chromedriver', preexec_fn, close_fds,
pass_fds, cwd, env,
startupinfo, creationflags, shell,
p2cread, p2cwrite,
c2pread, c2pwrite,
errread, errwrite,
restore_signals, start_new_session)
But it still raises the same exception: [WinError 193] %1 is not a valid Win32 application
This preventing the launch of chromedriver.
I even downloaded the latest version of chromedriver but ChromeDriver 2.43 (https://chromedriver.storage.googleapis.com/2.43/chromedriver_win32.zip) but the error persists.
Any clues on this one?

Ok so the chromedriver.exe needs to be placed in the ..\env\Scripts folder for this to work - specifying any system path entry did not work here.
When I place anything in over here, I can directly access it by process name. But i cannot use a listed path in system environment variables (or maybe I can but not aware how to :( ).

Related

Unzipping tar.gz in Google Colab

I was working in Google Colab and I wanted to unzip
detection checkpoints for tensorflow 2.x
ssd_mobilenet_v2_fpnlite_320x320_coco17_tpu-8.tar.gz
Here is the code:
!tar -xzvf ssd_mobilenet_v2_fpnlite_320x320_coco17_tpu-8.tar.gz
And after runing I got these errors:
/content/gdrive/My Drive/customTF2/data
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-35-5f662a73b4f6> in <module>
4
5 # !wget http://download.tensorflow.org/models/object_detection/tf2/20200711/ssd_mobilenet_v2_fpnlite_320x320_coco17_tpu-8.tar.gz
----> 6 get_ipython().system('tar -xzvf ssd_mobilenet_v2_fpnlite_320x320_coco17_tpu-8.tar.gz')
4 frames
/usr/lib/python3.8/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
1702 if errno_num != 0:
1703 err_msg = os.strerror(errno_num)
-> 1704 raise child_exception_type(errno_num, err_msg, err_filename)
1705 raise child_exception_type(err_msg)
1706
FileNotFoundError: [Errno 2] No such file or directory: '/bin/bash'
What can I do??
I tried anything but nothing helped.

How do I add chromedriver to PATH?

I'm trying to follow Automate the Boring Stuff and am trying to do the selenium work. I’m running Linux using Mu. Here's the code I'm trying to run
from selenium import webdriver
chromedriver = “/lorenmspeer/Downloads/chromedriver.exe”
browser = webdriver.Chrome(executable_path=chromedriver)
url = “https://www.duckduckgo.com”
browser.get(url)
I’m getting this error:
Traceback (most recent call last):
File “/home/lorenmspeer/.local/share/mu/mu_venv-38-20210401-164244/lib/python3.8/site-packages/selenium/webdriver/common/service.py”, line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File “/usr/lib/python3.8/subprocess.py”, line 854, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File “/usr/lib/python3.8/subprocess.py”, line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: ‘/lorenmspeer/Downloads/chromedriver.exe’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/lorenmspeer/mu_code/seleniumTest22.py”, line 5, in
browser = webdriver.Chrome(executable_path=chromedriver)
File “/home/lorenmspeer/.local/share/mu/mu_venv-38-20210401-164244/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py”, line 73, in init
self.service.start()
File “/home/lorenmspeer/.local/share/mu/mu_venv-38-20210401-164244/lib/python3.8/site-packages/selenium/webdriver/common/service.py”, line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: ‘chromedriver.exe’ executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
To check where Chrome driver is installed on Linux run whereis chromedriver. Then, put this path to Chrome("your_path")
In my project it is specified in the folder I defined:
driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver")
It should not have .exe resolution
For more info check docs:
https://chromedriver.chromium.org/getting-started
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.
I found a solution. First I had to make the file executable:
chmod +x chromedriver
Then I moved it to PATH
sudo mv chromedriver /usr/local/bin/
This made the code launch the browser.

How to troubleshoot python-selenium error “connection refused” when initializing a selenium webdriver?

I am trying to scrape a web site using Selenium, gecko driver and firefox. If I execute the script as root or as an ordinary user, it is working fine. But when I run it as apache (which is how it will be running in production), it is failing. Versions -
Mozilla Firefox 72.0
geckodriver 0.26.0
I have set log level to trace. Entries appearing in geckolog
1579004036460 mozrunner::runner INFO Running command: "/bin/firefox" "-marionette" "--disable-extensions" "--disable-infobars" "--disable-images" "--headless" "--disable-gpu" "--no-sandbox" "--disable-setuid-sandbox" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileKkQRyT"
1579004036461 geckodriver::marionette DEBUG Waiting 60s to connect to browser on 127.0.0.1:37317
*** You are running in headless mode.
(firefox:21013): dconf-CRITICAL **: 12:14:56.520: unable to create directory '/usr/share/httpd/.cache/dconf': Permission denied. dconf will not work properly.
(firefox:21013): dconf-CRITICAL **: 12:14:56.521: unable to create directory '/usr/share/httpd/.cache/dconf': Permission denied. dconf will not work properly.
(firefox:21013): dconf-CRITICAL **: 12:14:56.521: unable to create directory '/usr/share/httpd/.cache/dconf': Permission denied. dconf will not work properly.
(firefox:21013): dconf-CRITICAL **: 12:14:56.521: unable to create directory '/usr/share/httpd/.cache/dconf': Permission denied. dconf will not work properly.
(firefox:21013): dconf-CRITICAL **: 12:14:56.524: unable to create directory '/usr/share/httpd/.cache/dconf': Permission denied. dconf will not work properly.
1579004096533 mozrunner::runner DEBUG Killing process 21013
1579004096537 webdriver::server DEBUG <- 500 Internal Server Error {"value":{"error":"timeout","message":"connection refused","stacktrace":""}}
In the session where I am executing the script, this is the output
Traceback (most recent call last):
File "/var/www/html/***.py", line 36, in <module>
scrap_price()
File "/var/www/html/***.py", line 26, in scrap_price
driver = webdriver.Firefox(firefox_binary=binary, executable_path=gecko, options=options,firefox_profile=firefoxProfile, service_log_path='/tmp/geckodriver.log')
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: connection refused
Relevant sections of the code
options = Options()
options.add_argument('--disable-extensions')
options.add_argument('--disable-infobars')
options.add_argument('--disable-images')
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('--disable-setuid-sandbox')
options.log.level = 'trace'
gecko = os.path.normpath(os.path.join(os.path.dirname(__file__), 'geckodriver'))
binary = FirefoxBinary('/bin/firefox')
firefoxProfile = webdriver.FirefoxProfile()
firefoxProfile.set_preference('permissions.default.stylesheet', 2)
firefoxProfile.set_preference('permissions.default.image', 2)
firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so','false')
driver = webdriver.Firefox(firefox_binary=binary, executable_path=gecko, options=options,firefox_profile=firefoxPro
file, service_log_path='/tmp/geckodriver.log')
driver.get(urlpage)
OS is CentOS Linux release 7.6 with SELinux enabled. But sealert does not show any errors related to this.

CalledProcessError while installing Tensorflow using Bazel

I am trying to install Tensorflow from source using Bazel on Raspberry pi. I am following the official documentation as given here. When I run the ./configure in Tensorflow directory after completing all the steps written for Bazel, I get the following error
/home/cvit/bin/bazel: line 88: /home/cvit/.bazel/bin/bazel-real: cannot execute binary file: Exec format error
/home/cvit/bin/bazel: line 88: /home/cvit/.bazel/bin/bazel-real: Success
Traceback (most recent call last):
File "./configure.py", line 1552, in <module>
main()
File "./configure.py", line 1432, in main
check_bazel_version('0.15.0')
File "./configure.py", line 450, in check_bazel_version
curr_version = run_shell(['bazel', '--batch', '--bazelrc=/dev/null', 'version'])
File "./configure.py", line 141, in run_shell
output = subprocess.check_output(cmd)
File "/usr/lib/python2.7/subprocess.py", line 223, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['bazel', '--batch', '--bazelrc=/dev/null', 'version']' returned non-zero exit status 1
I didn't put the user flag in the bazel installation. So, I think this might be bazelrc error so I tried to set $PATH=$BAZEL/bin but nothing happened.
Please give any suggestion !!
Probably the problem is that the non appropriate version of bazel is installed.
Run bazel version in the tensorflow directory, and see if there is an error.
If there is a problem with bazel version, then check out the .baselversion file, and if it contains a version that isn't installable with apt, then dowload the installer from https://github.com/bazelbuild/bazel/releases then install it, else install with apt.
After that everything should work fine.

Unable to setup WebRTC native android code on ubuntu instance

Followed steps provided in this web page https://webrtc.org/native-code/android/
When I executed command "ninja -C out/Debug AppRTCMobile" I got following response
ninja: Entering directory `out/Debug'
ninja: fatal: chdir to 'out/Debug' - No such file or directory
I got stuck here and need help to continue in executing the next steps to complete the code setup.
Ubuntu version - 16.04.2
I have followed the same procedure once again to setup the code. This time I got a new error
Steps:
-> fetch --nohooks webrtc_android
-> gclient sync
-> gn gen out/Debug --args='target_os="android" target_cpu="arm"'
-> ninja -C out/Debug
ninja: Entering directory `out/Debug'
[1/8508] ACTION
//base:android_runtime_jni_headers__jni_Runtime(//build/toolchain/android:android_clang_arm)
FAILED: gen/android_runtime_jni_headers/base/jni/Runtime_jni.h python
../../base/android/jni_generator/jni_generator.py --depfile
gen/base/android_runtime_jni_headers__jni_Runtime.d --jar_file
../../third_party/android_tools/sdk/platforms/android-26/android.jar
--input_file java/lang/Runtime.class --ptr_type=long --output_dir gen/android_runtime_jni_headers/base/jni --includes
../../../../../../base/android/jni_generator/jni_generator_helper.h
--native_exports_optional
Traceback (most recent call last):
File "../../base/android/jni_generator/jni_generator.py", line 1428,
in
sys.exit(main(sys.argv))
File "../../base/android/jni_generator/jni_generator.py", line 1421,
in main
GenerateJNIHeader(input_file, output_file, options) File "../../base/android/jni_generator/jni_generator.py", line 1326, in
GenerateJNIHeader
jni_from_javap = JNIFromJavaP.CreateFromClass(input_file, options)
File "../../base/android/jni_generator/jni_generator.py", line 662,
in CreateFromClass
stderr=subprocess.PIPE)
File "/usr/lib/python2.7/subprocess.py", line 710, in init
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in
_execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
[3/8508] CC obj/third_party/boringssl/boringssl/v3_ncons.o
ninja: build stopped: subcommand failed.
Someone please help me in resolving this issue.
You have to generate the projects using GN before trying to compile. You have the instructions here:
https://webrtc.org/native-code/android/