HTTP scrip 307中的python临时重定向错误

2024-05-13 14:44:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我在脚本中使用了以下代码,代码在我的个人电脑上运行良好,但是如果我使用LAN(使用zscaler-防火墙/网关)并收到错误消息“临时重定向”,则这些代码不起作用。在

注意:我直接将url粘贴到浏览器中,注意到浏览器重定向到某个zscaler url(https://gateway.zscaler.net/auT?origurl=http%3AXXXX)并转到预期页面,该页面没有被阻止。在运行脚本和控件时不会发生相同的情况,但脚本块除外。在

有什么方法可以避免从我的脚本重定向/其他方法来避免错误?在

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)

Tags: 方法代码脚本httpurl错误username浏览器