I have been using a simple Python2.7 script using Selenium with Chromedriver to open a browser and download some files. Lately, I got an error saying that Chromedriver is outdated (Chrome version must be between 70 and 73) while my Chrome was ver. 75. So I downloaded ChromeDriver 75.0.3770.90 which should be OK for my Chrome version, but I got another error saying "selenium.common.exceptions.WebDriverException: Message: invalid argument: unrecognized capability: chromeOptions".
I have found some tips on the Internet saying that a way ChromeOptions should be used had changed, but I am unable to find how these changes exactly should look like in Python code. I'll be grateful for any helpful hint or solution.
def browser(full_url):
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
options = Options()
options.add_experimental_option("prefs", {
"download.default_directory": r"C:\Users\%s\AppData\Local\Temp\\" % getpass.getuser(),
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"safebrowsing.enabled": True
})
options.add_argument("--window-size=640,480")
driver = webdriver.Chrome(chrome_options=options)
try:
driver.get(full_url)
print("\nURL successfully Accessed\n")
time.sleep(9)
finally:
driver.close()
browser(full_url)
Error I got:
Traceback (most recent call last):
File "C:\Users\M\Documents\Skrypty\domains.py", line 59, in <module>
browser(full_url)
File "C:\Users\M\Documents\Skrypty\domains.py", line 46, in browser
driver = webdriver.Chrome(chrome_options=options)
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 98, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 188, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 256, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: invalid argument: unrecognized capability: chromeOptions
Just me guessing here but I encountered this as well. I used Python 2.7 and Selenium 3.4.1. I couldn't replicate the problem with Python 3.7 and with Selenium 3.14.0. So the changes lie probably in the changed Selenium. You should look into that.
EDIT: Yeah I just updated Selenium (to 3.14.0) and the problem went away. Now I got the driver working with both Python 2.7 and 3.7
Related
I ran the following code by installing selenium and django module.
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://localhost:8000')
assert 'Django' in browser.title
For the selenium module, I need geckodriver for firefox browser.
So, I installed geckodriver by different ways - 1. npm, 2. brew, 3. direct install (download from here and move it to /usr/local/bin or /usr/bin. All the ways did not work for the above test code.
I got the following error message:
Traceback (most recent call last):
File "functional_tests.py", line 3, in <module>
browser.get('http://localhost:8000')
File "/Users/kiyeonj/opt/anaconda3/envs/tdd_practice/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "/Users/kiyeonj/opt/anaconda3/envs/tdd_practice/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Users/kiyeonj/opt/anaconda3/envs/tdd_practice/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Reached error page: about:neterror?e=connectionFailure&u=http%3A//localhost%3A8000/&c=UTF-8&d=Firefox%20can%E2%80%99t%20establish%20a%20connection%20to%20the%20server%20at%20localhost%3A8000.
Please let me know what the problem is..
I think you need a gecko driver as well.
You can download from here
and put it into a folder, preferably where you have your .py files
and then use it like this :-
from selenium import webdriver
driver = webdriver.Firefox(executable_path = "D:\geckodriver.exe")
driver.maximize_window()
browser.get('http://localhost:8000')
assert 'Django' in browser.title
PS :
executable_path = 'full file path to your gecko driver'
On a Macbook Pro (Catalina), Python 3.8, interested in developing Android apps in Kivy using KivyMD. I took the following steps to install KivyMD:
create the virtual environment (virtmd), then activated it (source /virtmd/bin/activate)
in this virtual environment, installed the following via pip: Pillow, kivy
git-cloned KivyMD as per the link suggested on the GitHub page
Ran the pip install .
All this ran seamlessly with no hitch or errors. pip freeze shows the following installed items:
certifi==2021.5.30
charset-normalizer==2.0.4
docutils==0.17.1
idna==3.2
Kivy==2.0.0
Kivy-Garden==0.1.4
kivymd # file:///Users/robinhahn/PyProg/kvKivyMD/KivyMD
Pillow==8.3.1
Pygments==2.9.0
requests==2.26.0
urllib3==1.26.6
I was following a Codemy video tutorial and noticed that the presenter's pip freeze showed 4 more entries:
chardet==4.0.0
kivy-deps.angle==0.3.0
kivy-deps.glew==0.3.0
kivy-deps.sdl2==0.3.1
Cd'ed into the /demos/kitchen_sink folder, ran 'python3 main.py' which failed, raising this error, the last few lines of the traceback appear to focus on a file called kivytoast.py:
File "main.py", line 144, in <module>
KitchenSinkApp().run()
File "/Users/robinhahn/PyProg/kvKivyMD/virtmd/lib/python3.8/site-packages/kivy/app.py", line 949, in run
self._run_prepare()
File "/Users/robinhahn/PyProg/kvKivyMD/virtmd/lib/python3.8/site-packages/kivy/app.py", line 944, in _run_prepare
self.dispatch('on_start')
File "_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
File "main.py", line 65, in on_start
Builder.load_file(
File "/Users/robinhahn/PyProg/kvKivyMD/virtmd/lib/python3.8/site-packages/kivy/lang/builder.py", line 306, in load_file
return self.load_string(data, **kwargs)
File "/Users/robinhahn/PyProg/kvKivyMD/virtmd/lib/python3.8/site-packages/kivy/lang/builder.py", line 373, in load_string
parser = Parser(content=string, filename=fn)
File "/Users/robinhahn/PyProg/kvKivyMD/virtmd/lib/python3.8/site-packages/kivy/lang/parser.py", line 402, in __init__
self.parse(content)
File "/Users/robinhahn/PyProg/kvKivyMD/virtmd/lib/python3.8/site-packages/kivy/lang/parser.py", line 508, in parse
self.execute_directives()
File "/Users/robinhahn/PyProg/kvKivyMD/virtmd/lib/python3.8/site-packages/kivy/lang/parser.py", line 472, in execute_directives
mod = __import__(package)
File "/Users/robinhahn/PyProg/kvKivyMD/virtmd/lib/python3.8/site-packages/kivymd/toast/__init__.py", line 11, in <module>
from .kivytoast import toast
File "/Users/robinhahn/PyProg/kvKivyMD/virtmd/lib/python3.8/site-packages/kivymd/toast/kivytoast/__init__.py", line 3, in <module>
from .kivytoast import toast
File "/Users/robinhahn/PyProg/kvKivyMD/virtmd/lib/python3.8/site-packages/kivymd/toast/kivytoast/kivytoast.py", line 72, in <module>
class Toast(BaseDialog):
File "/Users/robinhahn/PyProg/kvKivyMD/virtmd/lib/python3.8/site-packages/kivymd/toast/kivytoast/kivytoast.py", line 90, in Toast
self, instance_label: Label, texture_size: list[int, int]
TypeError: 'type' object is not subscriptable
Still somewhat of a novice, and not really sure how to proceed from here.
ETA: I brought this up in VSCode and the last word:
list[int, int]
was squiggly-underlined, indicating it's the offending item. I have no idea what 'type' object is not subscriptable means or how to fix it.
Thanks to all who read and ponder this problem.
I'm on the same course right now and just got to that file with the same issue. I followed the path to the 'kivytoast.py' file and changed the following line (line 89):
def label_check_texture_size(self, instance_label: Label, texture_size: list([int, int])) -> NoReturn:
The kivymd devs seemed to have made a mistake and did list[int, int] instead of list([int,int]). You could also just leave it as [int,int] and it would work the same since it is alread in list format. Goodluck with the rest of your course!
Trying to run selenium for chrome through
/usr/bin/xvfb-run -a -e /tmp/selenium.log -w 0 /usr/bin/python2.7
and getting error like
(<class 'selenium.common.exceptions.WebDriverException'>, WebDriverException(), <traceback object at 0x7fc7cfc9c128>)
the strange thing is i am not even getting complete stack trace and the -e option for xvfb-run also is not returning any errors in file .
Here is my code
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
f = webdriver.ChromeOptions()
browser =webdriver.Chrome(executable_path='/home/local/chromedriver',chrome_options=f)
browser.get(url)
browser.quit()
i also tried with
executable_path='/usr/bin/chromedriver' and without executable_path
but getting the same error .
it was initially working with python 2.6 with firefox .
i checked maybe around 10-15 + similar questions even about how to enable more trace or debugging but none of the solutions seems to be doing the trick for me here.
selenium version 3.141.0
Edit :
i updated some code to be able to get complete stack trace and i got this error ,
WebDriverException: Message: The browser appears to have exited before
we could connect.
a bit more digging and saw its related to selenium/browser
installed old selenium version 2.53
thus above error was gone but now i am getting connection reset by peer error for everything , below is stack
(<class 'socket.error'>, error(104, 'Connection reset by peer'), <traceback object at 0x1e1e320>)
Traceback (most recent call last):
File "/var/www/Goose/src/goose/network.py", line 137, in get_html
browser.get(url)
File "/var/www/Goose/src/selenium/webdriver/remote/webdriver.py", line 245, in get
self.execute(Command.GET, {'url': url})
File "/var/www/Goose/src/selenium/webdriver/remote/webdriver.py", line 231, in execute
response = self.command_executor.execute(driver_command, params)
File "/var/www/Goose/src/selenium/webdriver/remote/remote_connection.py", line 395, in execute
return self._request(command_info[0], url, body=data)
File "/var/www/Goose/src/selenium/webdriver/remote/remote_connection.py", line 426, in _request
resp = self._conn.getresponse()
File "/usr/lib64/python2.6/httplib.py", line 1049, in getresponse
response.begin()
File "/usr/lib64/python2.6/httplib.py", line 433, in begin
version, status, reason = self._read_status()
File "/usr/lib64/python2.6/httplib.py", line 389, in _read_status
line = self.fp.readline(_MAXLINE + 1)
File "/usr/lib64/python2.6/socket.py", line 479, in readline
data = self._sock.recv(self._rbufsize)
error: [Errno 104] Connection reset by peer
even requests [security] is installed as i had seen one cause to be that .
solved it ,
the issue was the chrome browser and drivers were not properly installed , and their versions not compatible ,
installed latest chrome to run on the ami server using a script i got from
https://intoli.com/blog/installing-google-chrome-on-centos/
installed perfectly ,
added few key arguments ,
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('path to driver',chrome_options=chrome_options)
and viola it started working ,
I'm new in Python and I'm trying to use Selenium in Debian but it doesn't work, more concretely it seems to stay in a loop and nothing happens. The next script is the test that I've used:
#!/usr/bin/env python
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.python.org')
When I interrupt the script the following text appears:
Traceback (most recent call last):
File "prueba_parseo.py", line 7, in browser =
webdriver.Firefox() File
"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py",
line 154, in init
keep_alive=True)
File
"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
line 140, in init
self.start_session(desired_capabilities, browser_profile)
File
"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
line 229, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File
"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
line 295, 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 464, 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 488, in _request
resp = self._conn.getresponse()
File "/usr/lib/python2.7/httplib.py", line 1111, 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)
KeyboardInterrupt
I've been searching for an answer, but nothing works. I've changed the versions of the packages, export no_proxy="localhost,127.0.0.1"
OS: Debian 5
Python: 2.7
Selenium: 3.5
Geckodriver: 0.17.0
Firefox: 52.0
I don't know what else to do or what to change.
Thank you very much!
My guess is that it actually all goes well and the browser is started in background. The reason why it's staying open is probably because of the default option keep_alive=True I can see in your traceback.
Try closing the browser using browser.close() or browser.quit() when you are done with the tests.
From the documentation:
Finally, the browser window is closed. You can also call quit method
instead of close. The quit will exit entire browser whereas close`
will close one tab, but if just one tab was open, by default most
browser will exit entirely.
http://selenium-python.readthedocs.io/getting-started.html#simple-usage
I'm trying to install the CKAN ckanext-spatial plugin by following the step-by-step instructions listed below.
http://docs.ckan.org/projects/ckanext-spatial/en/latest/install.html#ubuntu-12-04-postgresql-9-1-and-postgis-1-5
After installation and configuration, I get the following apache server error when trying to access the site homepage. CKAN is currently unusable. Do I need to upgrade the version of GeoAlchemy or is this an issue with the extension?
mod_wsgi (pid=29881): Target WSGI script '/etc/ckan/default/apache.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=29881): Exception occurred processing WSGI script '/etc/ckan/default/apache.wsgi'.
Traceback (most recent call last):
File "/etc/ckan/default/apache.wsgi", line 10, in
application = loadapp('config:%s' % config_filepath)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 271, in loadobj
global_conf=global_conf)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 296, in loadcontext
global_conf=global_conf)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 320, in _loadconfig
return loader.get_context(object_type, name, global_conf)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 454, in get_context
section)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 476, in _context_from_use
object_type, name=use, global_conf=global_conf)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 406, in get_context
global_conf=global_conf)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 296, in loadcontext
global_conf=global_conf)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 328, in _loadegg
return loader.get_context(object_type, name, global_conf)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 620, in get_context
object_type, name=name)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 646, in find_egg_entry_point
possible.append((entry.load(), protocol, entry.name))
File "/usr/lib/ckan/default/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg/pkg_resources.py", line 1989, in load
entry = import(self.module_name, globals(),globals(), ['name'])
File "/usr/lib/ckan/default/src/ckan/ckan/config/middleware.py", line 26, in
from ckan.config.environment import load_environment
File "/usr/lib/ckan/default/src/ckan/ckan/config/environment.py", line 17, in
import ckan.model as model
File "/usr/lib/ckan/default/src/ckan/ckan/model/init.py", line 7, in
import vdm.sqlalchemy
File "/usr/lib/ckan/default/lib/python2.7/site-packages/vdm/sqlalchemy/init.py", line 32, in
from tools import Repository
File "/usr/lib/ckan/default/lib/python2.7/site-packages/vdm/sqlalchemy/tools.py", line 33, in
raise ValueError("VDM only works with SQLAlchemy versions 0.4 through 0.7, not: %s" % sqav)
ValueError: VDM only works with SQLAlchemy versions 0.4 through 0.7, not: 1.0.12
To reiterate the important bit, the error message says:
VDM only works with SQLAlchemy versions 0.4 through 0.7, not: 1.0.12
So it looks like you upgraded SQLAlchemy to the latest version somehow. This happens if you use the --upgrade flag when pip installing something, although the instructions you mention don't say to do that, so I'm not quite sure how you ended up with this version of SQLAlchemy.
I suggest you install the vdm and SQLAlchemy combination that is in the current ckan requirements which is currently:
pip install SQLAlchemy==0.9.6 vdm==0.13
and I believe this is backwards compatible with all ckan versions. (Remember to run pip with your virtualenv activated)
Fixed it using the following command to correct my version of sqlalchemy.
pip install -r /usr/lib/ckan/default/src/ckan/pip-requirements.txt.
This seemed to fix the error.