vendredi 29 juillet 2016

HTTP Error 307 - Temporary redirect in python script

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 (http://ift.tt/2akTksD) 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://ift.tt/2ak0ev4?'
    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://ift.tt/2akSNa1")
    #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)




Aucun commentaire:

Enregistrer un commentaire