title: urllib.error.HTTPError: HTTP Error 502: Bad Gateway PYTHON
body: <p>I am trying to open the Instagram URL using urllib.request.urlopen(url).read() but I am getting the error <strong>urllib.error.HTTPError: HTTP Error 502: Bad Gateway</strong></p>
  
  <pre class="lang-py prettyprint-override"><code>username = input('enter the username - ')
  url = "https://www.instagram.com/{}".format(username)
  html = urllib.request.urlopen(url).read()
  soup = BeautifulSoup(html, 'html.parser')
  </code></pre>
  
  <p>How can I solve this issue?</p>
  
  <p>EDIT:
  I got the solution and I have posted it. Cheers :)</p>