2016-03-10 138 views
1

我已經設置了在Ubuntu操作系統中使用python & Selenium新創建的Firefox配置文件的路徑。但是,當我運行python腳本,我得到一個錯誤Python Selenium設置路徑到Firefox的配置文件(Ubuntu的)

OSError: [Errno 13] Permission denied

我已經改變的文件到755權限和我仍然得到錯誤,也嘗試須藤。

sudo chmod 775 /home/student/.mozilla/firefox/gwi6uqpe.Default\ User2/ 

這是我的Python腳本的開始: -

from selenium import webdriver 
from selenium.webdriver.common.keys import Keys 
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary 
from selenium.webdriver.common.by import By 
import sys, time 
import time 

binary = FirefoxBinary('/home/student/.mozilla/firefox/gwi6uqpe.Default User2') 
browser = webdriver.Firefox(firefox_binary=binary) 

這是錯誤消息。

Traceback (most recent call last): 

文件 「default2.py」,第9行,在瀏覽器 = webdriver.Firefox(firefox_binary =二進制) 文件「/usr/local/lib/python2.7/dist-packages/selenium/webdriver /firefox/webdriver.py「,78行,init self.binary,timeout) 文件」/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py「 ,第51行,在init self.binary.launch_browser(self.profile,timeout = timeout) 文件「/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py 「第67行,位於launch_browser self._start_from_profile_path(self.profile.path) 文件「/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py」,第90行,in _start_from_profile_path ENV = self._firefox_env) 文件 「/usr/lib/python2.7/subprocess.py」,線710,在初始化 errread,ERRWRITE) 文件「/usr/lib/python2.7/subprocess .py「,第1327行,在_execute_child中 raise child_exception OSError:[Errno 13] Permission denied

請問我該如何解決這個問題。

回答

0

在我的機器上,〜/ .mozilla/firefox和它的子目錄有user:usergroup 700權限。你的腳本是由學生用戶執行的嗎?否則,它將被拒絕。作爲一個實驗,你可以嘗試給.mozilla/firefox和.mozilla/firefox/profiles 766權限。我不會運行這樣的生產環境,但可以創建一個具有權限的組,並將其他用戶添加到該組。

編輯:FirefoxBinary是不是什麼用於指定配置文件。使用FirefoxProfile代替:

profile = FirefoxProfile('/home/student/.mozilla/firefox/gwi6uqpe.Default') 
browser = webdriver.Firefox(firefox_profile=profile) 
+0

是腳本正在使用的學生用戶。我曾嘗試給766權限建議,但我仍然得到相同的錯誤。謝謝。 – Newbe

+0

我已檢查用戶對文件和文件夾的權限,並且都有rwx(讀寫執行) – Newbe

+0

感謝您的幫助。完美運作。 – Newbe

0
baseurl = "https://www.google.co.in/" 
    driver = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver') 
    driver.maximize_window() 
    driver.get(baseurl) 
+0

建議您在「 –

+0

」之間放置代碼請您提供一個解釋,說明爲什麼這可以幫助作者更好地理解您的解決方案。 –