Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python/Selenium:ERRNO 111当我多次调用我的函数时_Python_Selenium_Geckodriver - Fatal编程技术网

Python/Selenium:ERRNO 111当我多次调用我的函数时

Python/Selenium:ERRNO 111当我多次调用我的函数时,python,selenium,geckodriver,Python,Selenium,Geckodriver,我目前正在学习python,我很难处理一个函数的多次调用 使用硒与壁虎河 此代码在我使用一次时运行良好: from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By

我目前正在学习python,我很难处理一个函数的多次调用 使用硒与壁虎河

此代码在我使用一次时运行良好:

from selenium import webdriver
from selenium.webdriver.support.ui  import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.firefox.options import Options
import time
import sms

options = Options()
options.add_argument("--headless")
profile = webdriver.FirefoxProfile()
profile.set_preference("dom.disable_beforeunload", True)
browser = webdriver.Firefox(firefox_options=options, firefox_profile=profile)
timeout=10




def busETA(trajet):




    if trajet == "aller" :
        print('Recherche en cours du trajet aller...')
        Arret="Maison de retraite"
        #URL BONNEVILLE => CHAL

        URL='https://pysae.com/info/#/sm4cc/map/stop/5'
        browser.get(URL)
        #URL CHAL => BONNEVILLE
        #Arrêt Maison de retraite
        try :
            EtaPresent = EC.presence_of_element_located((By.CSS_SELECTOR, '.firstTime > span:nth-child(1)'))
            WebDriverWait(browser,timeout).until(EtaPresent)
            ETA = browser.find_element_by_css_selector('.firstTime > span:nth-child(1)').text
            if "H" not in ETA:
                ETA=ETA+' min'
            reponse = 'Le prochain bus arrivera dans '+str(ETA)+" à l'arrêt: "+Arret


        except WebDriverException as e:
            try :
                ETA = browser.find_element_by_css_selector('.text-endService').text
                reponse=ETA
            except WebDriverException as e:
                print("Error aller")
                ETA="Erreur"
                pass
        finally : 
            browser.quit()



    elif trajet =="retour" : 
        print('Recherche en cours du trajet retour...')
        Arret="CHAL"
        URL='https://pysae.com/info/#/sm4cc/map/stop/10'
        browser.get(URL)
        #Arrêt CHAL
        try :
            EtaPresent = EC.presence_of_element_located((By.CSS_SELECTOR, '.routes-view > footer:nth-child(2) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > span:nth-child(3) > span:nth-child(1) > span:nth-child(1)'))
            WebDriverWait(browser,timeout).until(EtaPresent)
            ETA= browser.find_element_by_css_selector('.routes-view > footer:nth-child(2) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > span:nth-child(3) > span:nth-child(1) > span:nth-child(1)').text
            if "H" not in ETA:
                ETA=ETA+' min'
            reponse = 'Le prochain bus arrivera dans '+str(ETA)+" à l'arrêt: "+Arret

        except WebDriverException as e:
            try :
                ETA = browser.find_element_by_css_selector('.text-endService').text
                reponse=ETA
            except WebDriverException as e:
                print("Erreur retour")
                ETA="Erreur"
                browser.quit()
                pass
        finally :  
            browser.quit()


    print(reponse)
    #sms.sendsms(reponse,'number')
    return

busETA('retour')
但如果我多次这样称呼它:

busETA('retour')
busETA('aller')
busETA('retour')
我得到这个错误:

    Recherche en cours du trajet retour...
Le prochain bus arrivera dans 26 min à l'arrêt: CHAL                                                                                                                                      
Recherche en cours du trajet retour...                                                                                                                                                    
Traceback (most recent call last):                                                                                                                                                        
  File "Pysae.py", line 90, in <module>                                                                                                                                                   
    busETA('retour')                                                                                                                                                                      
  File "Pysae.py", line 62, in busETA                                                                                                                                                     
    browser.get(URL)                                                                                                                                                                      
  File "/home/sirefen74/dev/python/ProxiPy/venv/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 332, in get                                                     
    self.execute(Command.GET, {'url': url})                                                                                                                                               
  File "/home/sirefen74/dev/python/ProxiPy/venv/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 318, in execute                                                 
    response = self.command_executor.execute(driver_command, params)                                                                                                                      
  File "/home/sirefen74/dev/python/ProxiPy/venv/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 472, in execute                                         
    return self._request(command_info[0], url, body=data)                                                                                                                                 
  File "/home/sirefen74/dev/python/ProxiPy/venv/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 495, in _request                                        
    self._conn.request(method, parsed_url.path, body, headers)                                                                                                                            
  File "/usr/lib/python3.5/http/client.py", line 1106, in request                                                                                                                         
    self._send_request(method, url, body, headers)                                                                                                                                        
  File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request                                                                                                                   
    self.endheaders(body)                                                                                                                                                                 
  File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders                                                                                                                      
    self._send_output(message_body)                                                                                                                                                       
  File "/usr/lib/python3.5/http/client.py", line 934, in _send_output                                                                                                                     
    self.send(msg)                                                                                                                                                                        
  File "/usr/lib/python3.5/http/client.py", line 877, in send                                                                                                                             
    self.connect()                                                                                                                                                                        
  File "/usr/lib/python3.5/http/client.py", line 849, in connect                                                                                                                          
    (self.host,self.port), self.timeout, self.source_address)                                                                                                                             
  File "/usr/lib/python3.5/socket.py", line 711, in create_connection                                                                                                                     
    raise err                                                                                                                                                                             
  File "/usr/lib/python3.5/socket.py", line 702, in create_connection                                                                                                                     
    sock.connect(sa)                                                                                                                                                                      
ConnectionRefusedError: [Errno 111] Connection refused
重新开始。。。
26分钟前到达的列车:CHAL
你可以去旅行。。。
回溯(最近一次呼叫最后一次):
文件“Pysae.py”,第90行,在
布塞塔('retour')
文件“Pysae.py”,第62行,在busETA中
browser.get(URL)
get中的文件“/home/sirefen74/dev/python/ProxiPy/venv/lib/python3.5/site packages/selenium/webdriver/remote/webdriver.py”,第332行
self.execute(Command.GET,{'url':url})
文件“/home/sirefen74/dev/python/ProxiPy/venv/lib/python3.5/site packages/selenium/webdriver/remote/webdriver.py”,执行中第318行
响应=self.command\u executor.execute(driver\u command,params)
文件“/home/sirefen74/dev/python/ProxiPy/venv/lib/python3.5/site packages/selenium/webdriver/remote/remote_connection.py”,第472行,在execute中
返回self.\u请求(命令信息[0],url,正文=数据)
文件“/home/sirefen74/dev/python/ProxiPy/venv/lib/python3.5/site packages/selenium/webdriver/remote/remote\u connection.py”,第495行,在请求中
self.\u conn.request(方法、解析的\u url.path、正文、标题)
请求中的文件“/usr/lib/python3.5/http/client.py”,第1106行
self.\u发送请求(方法、url、正文、标题)
文件“/usr/lib/python3.5/http/client.py”,第1151行,在发送请求中
self.endheaders(主体)
文件“/usr/lib/python3.5/http/client.py”,第1102行,在endheaders中
自发送输出(消息体)
文件“/usr/lib/python3.5/http/client.py”,第934行,在发送输出中
self.send(msg)
文件“/usr/lib/python3.5/http/client.py”,第877行,在send中
self.connect()
文件“/usr/lib/python3.5/http/client.py”,第849行,在connect中
(self.host、self.port)、self.timeout、self.source\u地址)
文件“/usr/lib/python3.5/socket.py”,第711行,在create_connection中
提出错误
文件“/usr/lib/python3.5/socket.py”,第702行,在create_connection中
sock.connect(sa)
def busETA(trajet):
browser = webdriver.Firefox(firefox_options=options)
[...]