title: Why am I getting connection refused exception for this Python script?
body: <p>I was writing a Python script to grab lyrics of a song from azlyrics using the request module. This is the script I wrote:</p>
  
  <pre><code>import requests, re
  from bs4 import BeautifulSoup as bs
  url = "http://search.azlyrics.com/search.php"
  payload = {'q' : 'shape of you'}
  r = requests.get(url, params = payload)
  soup = bs(r.text,"html.parser")
  try:
      link = soup.find('a', {'href':re.compile('http://www.azlyrics.com/lyrics/edsheeran/shapeofyou.html')})['href']
      link = link.replace('http', 'https')
      print(link)
      raw_data = requests.get(link)
  except Exception as e: 
      print(e)
  </code></pre>
  
  <p>but I got an exception stating :</p>
  
  <pre><code>Max retries exceeded with url: /lyrics/edsheeran/shapeofyou.html (Caused by NewConnectionError('&lt;requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7fbda00b37f0&gt;: Failed to establish a new connection: [Errno 111] Connection refused',))
  </code></pre>
  
  <p>I read on the internet that I am probably trying to send too many requests. So I made the script sleep for some time :</p>
  
  <pre><code>import requests, re
  from bs4 import BeautifulSoup as bs
  from time import sleep
  url = "http://search.azlyrics.com/search.php"
  payload = {'q' : 'shape of you'}
  r = requests.get(url, params = payload)
  soup = bs(r.text,"html.parser")
  try:
      link = soup.find('a', {'href':re.compile('http://www.azlyrics.com/lyrics/edsheeran/shapeofyou.html')})['href']
      link = link.replace('http', 'https')
      sleep(60)
      print(link)
      raw_data = requests.get(link)
  except Exception as e: 
      print(e)
  </code></pre>
  
  <p>but no luck!</p>
  
  <p>So I tried the same with urllib.request </p>
  
  <pre><code>import requests, re
  from bs4 import BeautifulSoup as bs
  from time import sleep
  from urllib.request import urlopen
  url = "http://search.azlyrics.com/search.php"
  payload = {'q' : 'shape of you'}
  r = requests.get(url, params = payload)
  soup = bs(r.text,"html.parser")
  try:
      link = soup.find('a', {'href':re.compile('http://www.azlyrics.com/lyrics/edsheeran/shapeofyou.html')})['href']
      link = link.replace('http', 'https')
      sleep(60)
      print(link)
      raw_data = urlopen(link).read()
  except Exception as e: 
      print(e)
  </code></pre>
  
  <p>but then got different exception stating :</p>
  
  <pre><code>&lt;urlopen error [Errno 111] Connection refused&gt;
  </code></pre>
  
  <p>Can anyone one tell me whats wrong with it and how do I fix it?</p>