PermissionError: [Errno 1] Operation not permitted while using Selenium with Pythonista on iOS - selenium

I want to create a program in pythonista that can control the web browser. I know Selenium is the best for this but I have tried it on pythonista for my iOS iPhone and I get an error.
This is the code:
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('http://www.yahoo.com')
Here is the error:
PermissionError: [Errno 1] Operation not permitted
Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/A2EBDF28-CB6C-4190-8199-7406AA3821A3/Pythonista3/Documents/selen.py", line 3, in <module>
browser = webdriver.Chrome()
File "/private/var/mobile/Containers/Shared/AppGroup/A2EBDF28-CB6C-4190-8199-7406AA3821A3/Pythonista3/Documents/site-packages-3/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
self.service.start()
File "/private/var/mobile/Containers/Shared/AppGroup/A2EBDF28-CB6C-4190-8199-7406AA3821A3/Pythonista3/Documents/site-packages-3/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/var/containers/Bundle/Application/24DD2A57-320E-4E21-9BE2-7C3605830DE0/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/subprocess.py", line 708, in __init__
restore_signals, start_new_session)
File "/var/containers/Bundle/Application/24DD2A57-320E-4E21-9BE2-7C3605830DE0/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/subprocess.py", line 1261, in _execute_child
restore_signals, start_new_session, preexec_fn)
PermissionError: [Errno 1] Operation not permitted

This error message...
PermissionError: [Errno 1] Operation not permitted
...implies that the ChromeDriver was unable to create a desired new resource e.g. logfile while initializing a new WebDriver and Web Client session.
As per the discussion Pythonista - Limitations due to iOS following are some of the limitations while using Pythonista :
No fork/exec for new processes. Impacts the subprocess module.
Due to missing fork, no full cleanup of process resources (memory, threads, file handles).
No file access outside of application directory.
No /dev/null and other special files.
Limited processing power of devices (compared to typical PC/Mac).
Process usually is stopped/killed after a while.
An simple example is as follows :
>>> import subprocess
>>> subprocess.call(["ls", "-l"])
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/mobile/Containers/Bundle/Application/8C59C68D-71BF-4CBB-90F8-373A1752DEE1/Pythonista.app/pylib/subprocess.py", line 524, in call
return Popen(*popenargs, **kwargs).wait()
File "/private/var/mobile/Containers/Bundle/Application/8C59C68D-71BF-4CBB-90F8-373A1752DEE1/Pythonista.app/pylib/subprocess.py", line 711, in __init__
errread, errwrite)
File "/private/var/mobile/Containers/Bundle/Application/8C59C68D-71BF-4CBB-90F8-373A1752DEE1/Pythonista.app/pylib/subprocess.py", line 1205, in _execute_child
self.pid = os.fork()
OSError: [Errno 1] Operation not permitted
What's wrong in your usecase
There can be 2 issues as follows :
When you invoke the following line of code :
browser = webdriver.Chrome()
The ChromeDriver tries to create/modify/access the scoped_directory within the file system. For example on Windows OS :
"chromedriverVersion": "2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73)",
"userDataDir": "C:\\Users\\username\\AppData\\Local\\Temp\\scoped_dir5188_12717"
Possibly ChromeDriver is unable to perform this task/method/functionality.
Again when you invoke the following line of code :
browser = webdriver.Chrome()
As per selenium.webdriver.chrome.webdriver ChromeDriver tries to create a logfile within the file system as per the constructor as follows :
class selenium.webdriver.chrome.webdriver.WebDriver(executable_path='chromedriver', port=0, options=None, service_args=None, desired_capabilities=None, service_log_path=None, chrome_options=None)
Possibly ChromeDriver is unable to perform this task/method/functionality,
Due to the above mentioned reasons you are seeing the error :
PermissionError: [Errno 1] Operation not permitted
Solution
Incase of any of the above mentioned cases the solution would be to restrict the access/creation of the resources within the application directory only.

Related

Python Selenuim Crashes

When I run my code it crashes please help and this was made late at night so I may have missed something obv. Instead of launching chrome driver like my other programs Ive made it runs actual chrome. is there a fix?
from selenium.webdriver.common.proxy import Proxy, ProxyType
import time
# change 'ip:port' with your proxy's ip and port
proxy_ip_port = '95.217.168.246:8888'
proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.http_proxy = proxy_ip_port
proxy.ssl_proxy = proxy_ip_port
capabilities = webdriver.DesiredCapabilities.CHROME
proxy.add_to_capabilities(capabilities)
# replace 'your_absolute_path' with your chrome binary absolute path
driver = webdriver.Chrome(r'C:\Users\andre\Desktop\Python dsicord bot\chromedriver',
desired_capabilities=capabilities)
driver.get('http://whatismyipaddress.com')
time.sleep(8)```
**Error:**
```DevTools listening on ws://127.0.0.1:57598/devtools/browser/120e371a-b935-4d04-9057-de3f728ce8b0
Traceback (most recent call last):
File "c:\Users\andre\Desktop\Python dsicord bot\sys.py", line 17, in <module>
driver = webdriver.Chrome(r'C:\Users\andre\Desktop\Python dsicord bot\chromedriver',
File "C:\Users\andre\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\Users\andre\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\andre\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\andre\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\andre\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 93
Current browser version is 92.0.4515.159 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe```
This error:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created:This version of ChromeDriver only supports Chrome version 93
is basically you do not have compatible version of browser and browser driver.
as of 29th-Aug-2021
Latest stable release: ChromeDriver 92.0.4515.107
and Google chrome browser version is Version 92.0.4515.159 (Official Build) (64-bit)
Download link for chromedriver, try to get 92.0, and that should help you past this issue.

driver.get(URL) not navigating to the specified URL

The webdriver is opening the browser but not navigating to the specified URL, and is returning the following exception:
Traceback (most recent call last):
File "C:/Users/91800/PycharmProjects/Automation/automation.py", line 3, in <module>
driver = webdriver.Chrome(executable_path='C:\\Program Files (x86)\\Google\Chrome\\Application\\chrome.exe')
File "C:\Users\91800\PycharmProjects\Automation\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\91800\PycharmProjects\Automation\venv\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
self.assert_process_still_running()
File "C:\Users\91800\PycharmProjects\Automation\venv\lib\site-packages\selenium\webdriver\common\service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service C:\Program Files (x86)\Google\Chrome\Application\chrome.exe unexpectedly exited. Status code was: 0
from selenium import webdriver
driver = webdriver.Chrome(executable_path='C:\\Program Files (x86)\\Google\Chrome\\Application\\chrome.exe')
driver.get('https://www.google.com/')
so first check whether your chrome version is the same as your web driver version..otherwise, there might be an issue executing the code
#to check the chrome version:
go to help in google chrome then to about google chrome and you will find a version there
#install the specific version of web driver from URL("https://chromedriver.chromium.org/downloads")
and...
it should be fine !!!

pgadmin4 showing 500 (INTERNAL SERVER ERROR)

I installed pgadmin4 (v4.4) package with from official Arch Linux package repository. It worked until the most recent update. Now I am not able to add a new server. In the browser I got the error:
http://127.0.0.1:36699/browser/server_group/children/1 500 (INTERNAL SERVER ERROR)
And from the server log, I got the error:
2019-04-09 21:41:49,900: ERROR flask.app: 'psycopg2.extensions.Column' object has no attribute '_asdict'
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/lib/python3.7/site-packages/flask/views.py", line 88, in view
return self.dispatch_request(*args, **kwargs)
File "/usr/lib/pgadmin4/web/pgadmin/browser/utils.py", line 259, in dispatch_request
return method(*args, **kwargs)
File "/usr/lib/pgadmin4/web/pgadmin/browser/utils.py", line 309, in children
children.extend(module.get_nodes(*args, **kwargs))
File "/usr/lib/pgadmin4/web/pgadmin/browser/server_groups/servers/__init__.py", line 127, in get_nodes
in_recovery, wal_paused = recovery_state(conn, manager.version)
File "/usr/lib/pgadmin4/web/pgadmin/browser/server_groups/servers/__init__.py", line 52, in recovery_state
status, result = connection.execute_dict(recovery_check_sql)
File "/usr/lib/pgadmin4/web/pgadmin/utils/driver/psycopg2/connection.py", line 1202, in execute_dict
desc.to_dict() for desc in cur.ordered_description()
File "/usr/lib/pgadmin4/web/pgadmin/utils/driver/psycopg2/connection.py", line 1202, in <listcomp>
desc.to_dict() for desc in cur.ordered_description()
File "/usr/lib/pgadmin4/web/pgadmin/utils/driver/psycopg2/cursor.py", line 94, in to_dict
ores = OrderedDict(self.orig_col._asdict())
AttributeError: 'psycopg2.extensions.Column' object has no attribute '_asdict'
I wonder if whether it is only me because I didn't get anything from google search.
I have the same issue psycopg2 2.8.1. Downgrade to 2.7.7 makes the trick.
pgAdmin4 team has released the new version pgadmin4 (v4.5) which will work with latest version of psycopg2 which is psycopg2 2.8.1
https://www.pgadmin.org/download/
Bug: https://redmine.postgresql.org/issues/4143
In my case, first attempt of execution of command /usr/pgadmin4/bin/setup-web.sh showed below error that caused the web URL to show 500 error.
/usr/pgadmin4/bin/setup-web.sh: line 87: semanage: command not found
I'm using AlamLinux. I installed the required package and ran setup-web.sh again to make the web URL working
yum install policycoreutils-python-utils
/usr/pgadmin4/bin/setup-web.sh

selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1

version:
firefox : Mozilla Firefox 61.0
geckodriver : geckodriver v0.20.1
I only tried below code:
from selenium import webdriver
browser = webdriver.Firefox()
But getting an error as below:
Traceback (most recent call last):
File "my.py", line 3, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
keep_alive=True)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 245, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 314, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status: 1
And geckodriver.log:
1528101123327 geckodriver INFO geckodriver 0.20.1
1528101123336 geckodriver INFO Listening on 127.0.0.1:43481
1528101124336 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-profile" "/tmp/rust_mozprofile.y93GPXwtXuKC"
Running Firefox as root in a regular user's session is not supported. ($XAUTHORITY is /home/username/.Xauthority which is owned by username.)
It's only makes a problem in root account , Please help..
This error message...
Running Firefox as root in a regular user's session is not supported. ($XAUTHORITY is /home/keti/.Xauthority which is owned by keti.)
...implies you were either trying to invoke Firefox Browser as a root user or running Firefox Browser as root in a non-root session.
As per User's Firefox process runs as root (if root is running Firefox) both the cases are not supported and should have been relatively difficult to achieve. But technically it was still possible (as the --new-instance and --no-remote flags are available to control remote control) but X11's permissive security model meant an user should basically treat the user account as if it had passwordless sudo.
There were a couple of issues associated as follows:
If a user runs Firefox as root but using their own home directory, many things become broken for that user, sometimes permanently.
When firefox is running as root, other users on the same display can gain root privileges
With the GA (General Availability) of Firefox v60.0 Mozilla Team decided to Disallow Firefox from running as sudo as:
Use clone() instead of fork() for sandboxed Linux processes and remove SandboxEarlyInit etc.
Earlier running sudo firefox, which previously seemed to work but was unsupported, now will fail to load content (tab crash on any page) on most Linux Distributions and it will fail to start and print a message as:
Running Firefox as root in a regular user's session is not supported. ($XAUTHORITY is /home/username/.Xauthority which is owned by username.)

How do I run headless selenium on Ubuntu Server

I'm trying to run headless selenium and to get to grips with it I've set up a new droplet on Digital Ocean (Ubuntu 16).
I am following this tutorial but I'm getting the following error when I run the script.
Traceback (most recent call last):
File "pyvirtualdisplaytest.py", line 12, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x7f981d0dc190>> ignored
What should I do? Thanks for your help.
Download the gecko driver from https://github.com/mozilla/geckodriver/releases/tag/v0.11.1
export PATH=$PATH:/loaction of the downloaded geckodriver
Run your Code.
If you get the following Exception
selenium.common.exceptions.WebDriverException: Message: Expected
browser binary location, but unable to find binary in default
location, no 'moz:firefoxOptions.binary' capability provided, and no
bina ry flag set on the command line
Kindly, check the geckodriver and firefox should be of either 32 or 64 bit
Otherwise. Provide the FirefoxBinary path in the code to the FirefoxDriver() using FireFoxBinary Object.