urllib3.exceptions.MaxRetryError:Ubuntu中的HTTPConnectionPool(host ='127.0.0.1',port = 53269)

时间:2019-05-04 18:56:29

标签: python python-2.7 selenium python-requests urllib3

我正在运行一个脚本,该脚本可在登录后从网站下载csv文件。我有多个帐户,并且试图一次循环访问,以便我可以一次运行脚本来下载所有csv。 因为第一个帐户脚本运行良好,然后我下载了csv,然后注销,然后再次从循环中设置新的登录名。但是从第二次开始我就跌倒了。

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=53269): Max retries exceeded with url: /session/307e4dd62b872c7bfbb59cbacea07b29/element (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f3a346b98d0>: Failed to establish a new connection: [Errno 111] Connection refused',))

下面是我的代码:

#! /usr/bin/python
# -*- coding: utf-8 -*-

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
import time
import csv
import os
import glob
import random
from datetime import date
import psutil
import requests
import json



options = Options()

print("satuts : script running")
PROCNAME = "chromedriver" # to clean up zombie Chrome browser

download_url = "download path"
options.add_experimental_option("prefs", {
  "download.default_directory": download_url,
  "download.prompt_for_download": False,
  "download.directory_upgrade": True,
  "safebrowsing.enabled": True
})

options.add_argument("download.default_directory = /usr/local/bin")
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'/usr/local/bin/chromedriver')
driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': download_url}}
command_result = driver.execute("send_command", params)
#open amazon url

driver.get("my url")
time.sleep(6)
def downloadCSV(store_id,user_name,user_password):
  global PROCNAME, driver
  start = datetime.datetime.now()
  driver.get("my url")

  driver.find_element_by_id('ap_email').send_keys(user_name)
  driver.find_element_by_id ('ap_password').send_keys(user_password)

  driver.find_element_by_id('signInSubmit').click()
  time.sleep(8)


  driver.get("my url")
  time.sleep(5)


  #select update status date
  driver.find_elements_by_css_selector("input[type='radio'][value='deliveryDate']")[0].click()
  time.sleep(6)


  select_box = Select(driver.find_element_by_xpath("//select[@id='shipStatusIdList']"))
  #get all options from dropdown

  dropdown_options = select_box.options

  #print("status : Shipping status selected")
  select_box = Select(driver.find_element_by_xpath("//select[@id='shipStatusIdList']"))
  x=[select_box.select_by_index(ele_index) for ele_index in range(len(dropdown_options)) ]
  time.sleep(8)


  # time.sleep(2)

  driver.find_element_by_id('downloadAsCSV').click()
  time.sleep(20)


  driver.find_element_by_class_name('log-out').click()
   # check whether the process name matches


  #get latest csv file
  list_of_files = glob.glob(download_url+'/*')
  latest_csv = max(list_of_files, key=os.path.getctime)
  today = date.today()
  new_file_name = "package_search_{}_10pm_{}_{}_{}.csv".format(store_id,today.day,today.month,today.year)

  os.rename(latest_csv,os.path.join(download_url,new_file_name))




  y=[proc.kill() for proc in psutil.process_iter() if proc.name() == PROCNAME]

list_of_data = [(1,'email id1','password1'),(2,'email id2','password2'),(3,'email id3','password3'),(4,'email id4','password4')........]

z=[downloadCSV(data[0],data[1],data[2]) for data in list_of_data]

driver.quit()
y=[proc.kill() for proc in psutil.process_iter() if proc.name() == PROCNAME]

我正在为此使用Selenium 3.141.0和python 2.7和chrome Web驱动程序运行脚本

有趣的是,该脚本在Windows中的所有帐户上都可以很好地运行,但是当我尝试在Ubuntu(Live Server)上运行时,它会出错。

我在Google的堆栈溢出问题上进行了搜索,但找不到答案。 谁能帮我吗?

0 个答案:

没有答案