问题
I have used below codes in my script, the code works fine in my personal PC, however the codes not work if i using LAN(using zscaler -firewall/gateway) and received error message "Temporary Redirect".
Note: i pasted the url directly in browser and noticed, browser redirects to some zscaler url (https://gateway.zscaler.net/auT?origurl=http%3AXXXX) and went to expected page and the page is not blocked. Same not happening while running script and control goes to except block of the script.
Is there any way to avoid the redirect from my script/ other way to avoid the error ?
url ='http://site24.way2sms.com/Login1.action?'
data = 'username='+username+'&password='+passwd+'&Submit=Sign+in'
# r = requests.get(url,allow_redirects=False)
# print r.url
#For cookies
cj= cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
p = opener.open("http://site24.way2sms.com/entry.action?id=ijrh&ec=0001&username=")
#print p.read()
#Adding header details
opener.addheaders=[('User-Agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120')]
try:
usock =opener.open(url, data)
except IOError as e:
print "error"
print(e.reason)
来源:https://stackoverflow.com/questions/38669984/http-error-307-temporary-redirect-in-python-script