问题
try:
client_result = urllib2.urlopen( "http://" + data['src_ip'] + "/iperf/iperf_main.py.fcgi", urllib.urlencode(data), 3 )
client_response_text = client_result.read()
return('200 OK', response_headers, ['success', server_response_text, client_response_text])
except urllib2.HTTPError as e:
return(str(e.code) + ' Error' , response_headers, [e.read()])
The code snippet above makes a HTTP POST request and gets a 307 redirect to the same address, except HTTPS version. However, the code control flow goes to the HTTPError exception. I thought the default HTTPRedirectHandler would automatically take care of this redirection. I don't care about the security implication of what I am doing (everything is encrypted in a lower layer anyway).
How can I redirect to the HTTPS page without handling it in the HTTPError code block? Thanks!
来源:https://stackoverflow.com/questions/44662147/how-to-handle-307-redirection-using-urllib2-from-http-to-https