HTTP Error 307 - Temporary redirect in python script

五迷三道 提交于 2021-01-28 19:02:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!