MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError:

I’m coding a script to track price products on Amazon. But my code only works well for about 15 minutes, and then appear above error!

This is my code:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.common.exceptions import TimeoutException
    from selenium.webdriver.support import expected_conditions as EC
    import smtplib
    from email.message import EmailMessage
    import time
    import chromedriver_binary
    
    def getinfo():
        options = Options()
        options.add_argument("--headless")
        options.add_argument('--no-sandbox')
        options.add_argument("--window-size=1280,720")
        options.add_argument("—disable-gpu")
        options.add_argument('--disable-dev-sh-usage')
        options.add_experimental_option('excludeSwitches', ['enable-logging'])

        driver = webdriver.Chrome(options=options)
    
        while True:
            driver.get(URL)
            try:
                element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 
        product_id)))
                break
            except TimeoutException:
                driver.quit()

        product_title = driver.find_element_by_id(product_id).text
        try:
            product_price = driver.find_element_by_id(price_id).text[1:]
        except:
            product_price = None

        driver.quit()
        return{
            "title": product_title,
            "price": product_price
        }
    while(True):

        URL = "https://www.amazon.com/gp/product/B08BB9RWXD"

        MAX_PRICE = '1000'

        product_id = 'productTitle'
        price_id = 'priceblock_ourprice'

        product_info = getinfo()
        time.sleep(60)

And this is errors:

Traceback (most recent call last):
  File "amztrack.py", line 77, in <module>
    product_info = getinfo()
  File "amztrack.py", line 34, in getinfo
    driver.get(URL)
  File "/home/huy/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "/home/huy/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 319, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/home/huy/.local/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 374, in execute
    return self._request(command_info[0], url, body=data)
  File "/home/huy/.local/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 397, in _request
    resp = self._conn.request(method, url, body=body, headers=headers)
  File "/home/huy/.local/lib/python3.6/site-packages/urllib3/request.py", line 80, in request
    method, url, fields=fields, headers=headers, **urlopen_kw
  File "/home/huy/.local/lib/python3.6/site-packages/urllib3/request.py", line 171, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "/home/huy/.local/lib/python3.6/site-packages/urllib3/poolmanager.py", line 336, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/home/huy/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 767, in urlopen
    **response_kw
  File "/home/huy/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 767, in urlopen
    **response_kw
  File "/home/huy/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 767, in urlopen
    **response_kw
  File "/home/huy/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 727, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/home/huy/.local/lib/python3.6/site-packages/urllib3/util/retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=44161): Max retries exceeded with url: /session/e4bd55bc7faa50b6b53da1241507180c/url (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f07332539b0>: Failed to establish a new connection: [Errno 111] Connection refused',))

I thought I request many times in the same period time by one IP, Is this the reason Amazon block me?
Thanks so much for any solution to this problem!

Source: Python-3x Questions

LEAVE A COMMENT