title: How to address urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=58408): Max retries exceeded with url
body: <p>I am trying to scrape a few pages of a website with selenium and use the results but when I run the function twice</p>
  <pre><code>[WinError 10061] No connection could be made because the target machine actively refused it'
  </code></pre>
  <p>Error appears for the 2nd function call.
  Here's my approach :</p>
  <pre><code>import os
  import re
  from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.chrome.options import Options
  from bs4 import BeautifulSoup as soup
  
  opts = webdriver.ChromeOptions()
  opts.binary_location = os.environ.get('GOOGLE_CHROME_BIN', None)
  opts.add_argument(&quot;--headless&quot;)
  opts.add_argument(&quot;--disable-dev-shm-usage&quot;)
  opts.add_argument(&quot;--no-sandbox&quot;)
  browser = webdriver.Chrome(executable_path=&quot;CHROME_DRIVER PATH&quot;, options=opts)
  
  lst =[]
  def search(st):
      for i in range(1,3):
          url = &quot;https://gogoanime.so/anime-list.html?page=&quot; + str(i)
          browser.get(url)
          req = browser.page_source
          sou = soup(req, &quot;html.parser&quot;)
          title = sou.find('ul', class_ = &quot;listing&quot;)
          title = title.find_all(&quot;li&quot;)
          for j in range(len(title)):
              lst.append(title[j].getText().lower()[1:])
      browser.quit()
      print(len(lst))
      
  search(&quot;a&quot;)
  search(&quot;a&quot;)
  </code></pre>
  <p><strong>OUTPUT</strong></p>
  <pre><code>272
  raise MaxRetryError(_pool, url, error or ResponseError(cause))
  urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=58408): Max retries exceeded with url: /session/4b3cb270d1b5b867257dcb1cee49b368/url (Caused by NewConnectionError('&lt;urllib3.connection.HTTPConnection object at 0x000001D5B378FA60&gt;: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
  </code></pre>