I have python3 code, that works in Windows OS, but doesn't on raspberry pi4
Maybe anybody can help?
import time
import os
from webbot import Browser
web = Browser()
web.go_to('https://xxxxxxx')
#time.sleep(1)
web.type('cccccccc', into = 'email')
#time.sleep(1)
web.type('dddddddd', into = 'password', id='edit-pass')
web.click('submit', id='edit-submit')
In windows OS this works, but on Raspberry Pi OS it is returning answer
%Run eso.py Traceback (most recent call last): File "/home/pi/ESO/eso.py", line 5, in <module>
web = Browser() File "/usr/local/lib/python3.7/dist-packages/webbot/webbot.py", line 66, in
__init__
os.chmod(driverpath, 0o755) PermissionError: [Errno 1] Operation not permitted: '/usr/local/lib/python3.7/dist-packages/webbot/drivers/chrome_linux'
Any things?
After trying to make changes by answer, i get this:
pi#raspberrypi:~/ESO $ sudo python3 eso.py
Traceback (most recent call last):
File "eso.py", line 5, in <module>
web = Browser()
File "/usr/local/lib/python3.7/dist-packages/webbot/webbot.py", line 68, in __init__
self.driver = webdriver.Chrome(executable_path=driverpath, options=options)
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: '/usr/local/lib/python3.7/dist-packages/webbot/drivers/chrome_linux'
u may try using a module called webbrowser or
as the error says its not getting the right permition so do this :
open terminal
type " cd (where u have stored ur file)"
type " sudo python3 (filename).py"
thats it
Solved by changing method from webbot to selenium
Related
I am working on a script to analysis proteins. One of the def if for creating a makeblastdb, and then use it to carry out blast. The code is as below:
import subprocess
from Bio import SeqIO
from Bio.Blast.Applications import NcbiblastnCommandline
def blast_file(input_data_files, db_files, output):
input_data_files = opts.input_file + '/protein_extracted_file.fa'
db_files = opts.input_file +'/alleles_reference_db'
cmd = ["makeblastdb", "-in", db_files, "-dbtype", "prot", "-parse_seqids", "-out", output + "/temporary_db",
"-title", "temporary_db"]
my_file = subprocess.Popen(cmd)
my_file.wait()
blasttn_cline = NcbiblastnCommandline(query=input_data_files, subject=db_files, evalue=0.001, outfmt=5,
out=output + '/blast_output.xml')
blasttn_cline()
The script works well until it get to the above def, and I get the error message:
Traceback (most recent call last):
**> File "open.py", line 234, in <module>
> main() File "open.py", line 229, in main
> blast_file(input_data_files, db_files, output) File "open.py", line 165, in blast_file
> my_file = subprocess.Popen(cmd)
File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 709, in __init__
> restore_signals, start_new_session) File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 997, in
> _execute_child
> startupinfo) FileNotFoundError: [WinError 2] The system cannot find the file specified**
How can I make this to work for python3? Originally the script was written in python2.7, and I have updated most of it but I am stuck in this area. Any suggestion to update it?
I'm trying to setup Selenium with Python and Eclipse on my home computer but I keep getting the following 2 trace back errors. I know part of it is that the "geckodriver.exe" file is not in the correct path but I don't know where to move it to so its correct and what the "FileNotFoundError: [WinError 2] The system cannot find the file specified" error refers to.
Program:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
user_name = "123#gmail.com"
password = "Password123"
driver = webdriver.Firefox()
driver.get("https://www.facebook.com")
element = driver.find_element_by_id("email")
element.send_keys(user_name)
element = driver.find_element_by_id("pass")
element.send_keys(password)
element.send_keys(Keys.RETURN)
element.close()
Console Error Msg:
Traceback (most recent call last):
File "C:\Users\Owner\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\Owner\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 947, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,<br />
File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1416, 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\Owner\eclipse-workspace\PyDev1\PyDevPackage\PyDevModule.py", line 10, in <module>
driver = webdriver.Firefox()
File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
self.service.start()
File "C:\Users\Owner\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.
I am trying to run a bash script in my python script, I'm sure there is a way to do what my bash script is doing in python instead but I am more focused on getting this working.
Here is the code I am running as root followed by the error:
import subprocess
#variable = subprocess.check_output('dmidecode', shell=True)
#print(variable)
#run program once as root then cron it as root
try :
file = open("/var/log/serialcontrol/dmidecode.txt", "r")
except FileNotFoundError:
file = open('/var/tmp/serialcontrol.bash', 'w')
file.write("#!/bin/bash/\nif [ ! -d /var/log/serialcontrol/]\nthen\n\tmkdir /var/log/serialcontrol/\nfi");
file.close()
subprocess.call("/var/tmp/serialcontrol.bash")
Heres the error
Traceback (most recent call last):
File "/home/trisimix/serialcontrol/serialcontrol.py", line 6, in <module>
file = open("/var/log/serialcontrol/dmidecode.txt", "r")
FileNotFoundError: [Errno 2] No such file or directory: '/var/log/serialcontrol/dmidecode.txt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/trisimix/serialcontrol/serialcontrol.py", line 11, in <module>
subprocess.call("/var/tmp/serialcontrol.bash")
File "/usr/lib/python3.5/subprocess.py", line 557, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied
The /var/tmp/serialcontrol.bash file that you create while handling the FileNotFoundError is not executable. Make it executable first before trying to execute it with subprocess.
import subprocess
import os
import stat
#variable = subprocess.check_output('dmidecode', shell=True)
#print(variable)
#run program once as root then cron it as root
try :
file = open("/var/log/serialcontrol/dmidecode.txt", "r")
except FileNotFoundError:
script = '/var/tmp/serialcontrol.bash'
with open(script, 'w') as file:
file.write("#!/usr/bin/env bash/\nif [ ! -d /var/log/serialcontrol/]\nthen\n\tmkdir /var/log/serialcontrol/\nfi");
st = os.stat(script)
os.chmod(script, st.st_mode | stat.S_IEXEC)
subprocess.call(script)
As #anishsane pointed out in a comment, another alternative to chmod-ing the script is to call it like this, and just drop the chmod:
subprocess.call(["/bin/bash", script])
Actually, if we can assume that bash is on PATH, then this would be more portable:
subprocess.call(["bash", script])
Software version details:
Python: 2.7.12
OS: Windows 10.
Selenium: selenium-2.53.6
Firefox: 47.0
Code snippet:
import sys, urllib2
from selenium import webdriver
driver = webdriver.Firefox()
The last line throws this error:
Traceback (most recent call last): File "queryWebsite.py", line 8,
in
driver = webdriver.Firefox()
File
"C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py",
line 80, in __ init __
self.binary, timeout) File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py",
line 48, in __ init __
self.profile.update_preferences() File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_profile.py",
line 97, in update_preferences
self._write_user_prefs(self.default_preferences) File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_profile.py",
line 221, in _write_user_prefs
with open(self.userPrefs, "w") as f:
IOError: [Errno 22] invalid mode ('w') or filename:
'c:\users\xyz\appdata\local\temp\tmpgwa_ot\user.js'
Any idea what is going wrong here?
I had a problem running executing a Webdriver using a script in python using the library selenium. I have posted the sample code scenarios as well as the corresponding error thrown while executing.
Code Scenario:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
Error Scenario:
Traceback (most recent call last):
File "C:/Users/Kaushik/Desktop/IMC DEVELOPER TEST/Sample.py", line 4, in <module>
driver = webdriver.Firefox()
File "C:\Python27\lib\site-packages\selenium-2.37.2-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 59, in __init__
self.binary, timeout),
File "C:\Python27\lib\site-packages\selenium-2.37.2-py2.7.egg\selenium\webdriver\firefox\extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "C:\Python27\lib\site-packages\selenium-2.37.2-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 60, in launch_browser
self._start_from_profile_path(self.profile.path)
File "C:\Python27\lib\site-packages\selenium-2.37.2-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 83, in _start_from_profile_path
env=self._firefox_env).communicate()
File "C:\Python27\lib\subprocess.py", line 709, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 957, in _execute_child
startupinfo)
WindowsError: [Error 87] The parameter is incorrect
I coudnt understand the Error thrown. I just need to use the selenium library to retrieve a dynamic data from a website using a python script.
There is nothing wrong with your code, it works fine for me.
Do you have firefox installed? if not, you can use a different browser. for example:
driver = webdriver.Ie
or
driver = webdriver.Opera