title: How to get redirect url?
body: <p>I am using urllib.request to perform a sequence of http calls in python 3.6. I need to retrieve the value of a 302 http redirect that is returned in response to a urllib.request.urlopen call like so...</p>
  
  <pre><code>import urllib.request
  
  ... many previous http calls ...
  
  post_data = {'foo': 'bar', 'some': 'otherdata'}
  encoded = urllib.parse.urlencode(post_data).encode('utf-8')
  req = urllib.request.Request('https://some-url', encoded)
  redirected_url = urllib.request.urlopen(req).geturl()
  </code></pre>
  
  <p>I get an error like...</p>
  
  <pre><code>urllib.error.HTTPError: HTTP Error 302: Found - Redirection to url 'gibberish://login_callback?code=ABCD......' is not allowed
  </code></pre>
  
  <p>What I need is to actually get the url that is being returned in the 302 as the .geturl() method should provide, but instead I get an error.  </p>
  
  <p>Please no answers like "Hey use this other library that I'm super into right now" as we've spent a long time building this script using urllib2 and we have very little python knowledge. </p>
  
  <p>Thanks for your help.     </p>