执行python脚本

时间:2016-07-28 07:01:08

标签: python browser http-headers firewall

我正在尝试使用python脚本通过way2sms发送短信,脚本如下所示,

 #logging into the sms site
    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 "Message"
        print(e.reason)
    #return()

    print cj 
    jession_id =str(cj).split('~')[1].split(' ')[0]
    send_sms_url = 'http://site24.way2sms.com/smstoss.action?'
    send_sms_data = 'ssaction=ss&Token='+jession_id+'&mobile='+number+'&message='+message+'&msgLen=136'
    opener.addheaders=[('Referer', 'http://site25.way2sms.com/sendSMS?Token='+jession_id)]
    try:
        sms_sent_page = opener.open(send_sms_url,send_sms_data)
    except IOError:
        print "error"
        #return()

    print "success" 
    #return ()

以上代码在我的个人电脑上运行良好,但是相同的代码会在我的办公室PC中产生临时重定向警告,并且短信没有发送。这可能是由于防火墙/任何其他浏览器配置吗?

>>> execfile('test.py')
Enter text: Test SMS
Enter number: 81XXXXX
Message
**Temporary Redirect**
<CookieJar[<Cookie _sm_au_d=1 for .way2sms.com/>, <Cookie JSESSIONID=A05~F1387E4B5D9E33EC5EEBC6A698D430E6.w805 for site24.way2sms.com/>]>
success
>>> 

提前致谢

0 个答案:

没有答案