Python Reliance Broadband自动登录脚本-在Windows上运行时出现语法错误
我正在使用Reliance Broadband,它有基于web的登录来访问internet。它每24小时注销一次,所以我必须再次登录 我遇到了一个,它不断检查连接并保持连接活动 不知怎的,当我在安装了最新Python版本后在windows上运行它时,我得到了以下语法错误Python Reliance Broadband自动登录脚本-在Windows上运行时出现语法错误,python,shell,ssh,autologin,Python,Shell,Ssh,Autologin,我正在使用Reliance Broadband,它有基于web的登录来访问internet。它每24小时注销一次,所以我必须再次登录 我遇到了一个,它不断检查连接并保持连接活动 不知怎的,当我在安装了最新Python版本后在windows上运行它时,我得到了以下语法错误 C:\Documents and Settings\CS\Desktop>reliance-login.py File "C:\Documents and Settings\CS\Desktop\reliance-l
C:\Documents and Settings\CS\Desktop>reliance-login.py
File "C:\Documents and Settings\CS\Desktop\reliance-login.py", line 48
if debug: print "Testing"
^
SyntaxError: invalid syntax
有人能检查一下,让我知道到底是什么问题吗
=====
感谢sr2222,在删除所有+n-…之后,我尝试了2to3。。。我仍然得到一些错误 以下是2to3之后的脚本。。你能在你的机器上运行它吗
#!/usr/bin/env python
# encoding: utf-8
"""
# Reliance Login Script for Python 2.x v1.0
#
# Copyright (c) 2009 Kunal Dua, http://www.kunaldua.com/blog/?p=330
# Copyright (c) 2012 Anoop John, http://www.zyxware.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
"""
import urllib.request, urllib.error, urllib.parse, urllib, http.cookiejar, time, re, sys
username = 'username'
password = 'password'
req_headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; U; ru; rv:5.0.1.6) Gecko/20110501 Firefox/5.0.1 Firefox/5.0.1'
}
request = urllib.request.Request(url, headers=req_headers)
if not opener:
jar = http.cookiejar.FileCookieJar("cookies")
opener = urllib.request.build_opener(urllib2.HTTPCookieProcessor(jar))
response = opener.open(request, data)
code = response.code
headers = response.headers
def is_internet_on():
'''test if the machine is connected to the internet'''
if debug: print("Testing")
try:
code, headers, html, opener = get_url('http://74.125.113.99', timeout=10)
if debug: print(html)
if re.search('google.com', html):
return True
else:
return False
except:
if debug: print("Error")
return False
return False
def internet_connect():
'''try to connect to the internet'''
code, headers, html, cur_opener = get_url("http://10.239.89.15/reliance/startportal_isg.do", timeout=10)
if debug: print(html)
login_data = urllib.parse.urlencode({'userId' : username, 'password' : password, 'action' : 'doLoginSubmit'})
code, headers, html, cur_opener = get_url('http://10.239.89.15/reliance/login.do', data=login_data, opener=cur_opener)
if debug: print(html)
def internet_disconnect():
'''try to disconnect from the internet'''
code, headers, html, cur_opener = get_url('http://10.239.89.15/reliance/login.do', timeout=10)
if debug: print(html)
code, headers, html, cur_opener = get_url('http://10.239.89.15/reliance/logout.do', opener=cur_opener)
if debug: print(html)
def internet_keep_alive():
'''login and keep the connection live'''
while True:
if not is_internet_on():
internet_connect()
if debug: print("Not connected")
else:
if debug: print("Connected")
pass
time.sleep(check_interval)
def print_usage():
print("Reliance Netconnect AutoLogin")
print("-----------------------------")
print("usage:" + sys.argv[0] + " [login|logout]\n")
print("If there are no arguments it runs in an infinite loop and will try to remain connected to the internet.")
keep_alive = True
if (len(sys.argv) > 1):
你下载了Python2还是Python3?这就是Python2.X打印语法,如果您有Python3解释器,您将看到该错误。该脚本可能是用Python2.X编写的。您可以下载不同的解释器,或者在保持活动状态脚本的源代码上运行2to3.py脚本,以使其在Python 3下工作
还有,哇,还有ISP还在这么做吗?很抱歉,您被卡住了。谢谢sr2222,在删除所有+n-…之后,我尝试了2to3。。。我仍然得到一些错误。以下是2to3之后的脚本。。你能在你的机器上运行它吗。我不知道如何发布我转换的脚本。