I am trying to schedule my script on pythonanywhere with a beginner account.
Here is my code
class SeeTicket(webdriver.Chrome):
def __init__(self ,driver_path='/home/saifbyte/seetickets/chromedriver.exe', teardown = False):
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
options.add_experimental_option( 'excludeSwitches' , ['enable-logging'])
options = options
self.driver_path = driver_path
self.teardown = teardown
super(SeeTicket , self).__init__(options = options , executable_path=self.driver_path)
self.maximize_window()
but when I am scheduling this task , i get the following error:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
whole traceback:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "/usr/local/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.9/subprocess.py", line 1821, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: '/home/saifbyte/seetickets/chromedriver.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/saifbyte/seetickets/seeticket_script.py", line 3, in <module>
st = SeeTicket()
File "/home/saifbyte/seetickets/Scrapers/seeticket.py", line 20, in __init__
super(SeeTicket , self).__init__(options = options , executable_path=self.driver_path)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 86, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
My executable path is correct but still getting error.
Alternatively are there any good alternative to pythonanywhere.
Thanks
From the Traceback I observe a linux styled path:
/home/saifbyte/seetickets/...
Presumably an non windows system.
Solution
You need to drop the extension of the ChromeDriver binary executable. Your effective line of code will be:
def __init__(self ,driver_path='/home/saifbyte/seetickets/chromedriver', teardown = False):
Related
I am using python 3.8.5 as well as the latest version of imagemagick and moviepy
error (vs code):
Traceback (most recent call last):
File "C:\Users\edgib102\AppData\Local\Programs\Python\Python38-32\lib\site-packages\moviepy\video\VideoClip.py", line 1137, in __init__
subprocess_call(cmd, logger=None)
File "C:\Users\edgib102\AppData\Local\Programs\Python\Python38-32\lib\site-packages\moviepy\tools.py", line 46, in subprocess_call
proc = sp.Popen(cmd, **popen_params)
File "C:\Users\edgib102\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\edgib102\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, 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/edgib102/source/repos/Reddit-tts-video/Python/GetComments.py", line 40, in <module>
TextClip = TextClip('TextTxt', fontsize=100, color = 'white')
File "C:\Users\edgib102\AppData\Local\Programs\Python\Python38-32\lib\site-packages\moviepy\video\VideoClip.py", line 1146, in __init__
raise IOError(error)
OSError: MoviePy Error: creation of None failed because of the following error:
[WinError 2] The system cannot find the file specified.
.This error can be due to the fact that ImageMagick is not installed on your computer, or (for Windows users) that you didn't specify the path to the ImageMagick binary in file conf.py, or that the path you specified is incorrect
Code:
TextClip = TextClip('TextTxt', fontsize=100, color = 'white')
TextClip = TextClip.set_position('center').set_duration(10)
Any help at all would be much appreciated, also full code here
Solved. Just need to set the magick.exe file path as the variable inside default_config.py. You can find it in the moviepy folder.
Add the magick.exe path to IMAGEMAGICK_BINARY in config_defaults.py.
By default it should look like this
IMAGEMAGICK_BINARY = os.getenv('IMAGEMAGICK_BINARY', 'auto-detect')
After
IMAGEMAGICK_BINARY = os.getenv('IMAGEMAGICK_BINARY', 'C:\\Program Files\\ImageMagick_VERSION\\magick.exe')
#Function to click a button on DocDroid website
def sendpdf():
import selenium
driver=webdriver.Chrome()
driver.get('https://www.docdroid.net/')
upload_box=driver.find_element_by_id('select')
upload_box.click()
sendpdf()
if I add 'from selenium import webdriver' I get the following error:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1307, 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/User/Desktop/Computer Projects/Virus/pdfsend.py", line 11, in <module>
sendpdf()
File "C:/Users/User/Desktop/Computer Projects/Virus/pdfsend.py", line 6, in sendpdf
driver=webdriver.Chrome()
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
>>>
I'm for some reason getting the following error:
NameError: name 'webdriver' is not defined
packages\selenium\webdriver\chrome\webdriver.py", line 73, in init
self.service.start()
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
You need to add chromedriver in your system PATH, you can download it from here
How can I install firefox web driver to work with selenium\python
I installed it with the command
pip install selenium
I tried this code:
driver=webdriver.Firefox()
driver.get("https://www.google.com")
content=driver.find_element_by_id("lga")
print(content)
But it gives me this error
Traceback (most recent call last):
File "C:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\site-package
s\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\subprocess.p
y", line 775, in __init__
restore_signals, start_new_session)
File "C:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\subprocess.p
y", line 1178, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".\Class.py", line 3, in <module>
class Scrape:
File ".\Class.py", line 4, in Scrape
driver = webdriver.Firefox()
File "C:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\site-package
s\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
self.service.start()
File "C:\Users\Acer\AppData\Local\Programs\Python\Python37-32\lib\site-package
s\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable
needs to be in PATH.
A few things to check out.
1) you need to make sure you have install Firefox.
2) Get the latest gecko driver here
3) Set path in your environment
export PATH=$PATH:/path/to/directory/of/executable/geckodriver<br>
4) If you intend to skip 3 , you need to amend this in the your script
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('C:\Firefox\Firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)
The following piece of code was working fine for a year, of late it intermittently started failing with following error, wonder if any OS or hardware change is causing this
import subprocess
def bash_command(cmd):
process = subprocess.Popen(cmd, shell=True, executable="/bin/bash")
process.wait()
bash_command("bash myscript.sh")
The error message is:
Traceback (most recent call last): File
"/Users/ishandutta2007/Documents/Projects/p2/shell_way/all_in_one_refill.py",
line 68,
bash myscript.sh File "/Users/ishandutta2007/Documents/Projects/p2/shell_way/all_in_one_refill.py",
line 31, in bash_command
process = subprocess.Popen(cmd, shell=True, executable="/bin/bash") File
"/Users/ishandutta2007/.pyenv/versions/3.6.0/lib/python3.6/subprocess.py",
line 707, in __init__
restore_signals, start_new_session) File "/Users/ishandutta2007/.pyenv/versions/3.6.0/lib/python3.6/subprocess.py",
line 1326, in _execute_child
raise child_exception_type(errno_num, err_msg) OSError: [Errno 9] Bad file descriptor
completeProcess = subprocess.run("la")
This is my code to run commands via python, and it raise this error:
Traceback (most recent call last):
File "script_senior.py", line 171, in <module>
completeProcess = subprocess.run("la") # doesn't capture output
File "/usr/lib/python3.5/subprocess.py", line 693, in run
with Popen(*popenargs, **kwargs) as process:
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)
FileNotFoundError: [Errno 2] No such file or directory: 'la'
My OS is ubuntu, and when enter "la" in terminal, it will list files(include hidden files) in current working directory. and "ll" cmd will list file details. but I can't use them in python's subprocess api
How can I achieve this function? Is there any common api to run commands or just the python didn't recognize "la"
la is an alias for 'ls -A'. That comes as a default shell alias in systems like Ubuntu. If you wanna run it just use:
completeProcess = subprocess.run(["ls","-A"])
and if you are looking for the stdout you can use something like:
completeProcess = subprocess.run(["ls","-A"] , stdout=subprocess.PIPE)
print(completeProcess.stdout.decode())