python - 如何在 Linux 上修复 Python 中的 Except 错误

标签 python linux

我正在尝试从 Linux 执行 python 脚本,但我一直在 except 行上收到此错误。有人能解决这个问题吗?

$ python pygeo_ip.py

def search(self):


    message = ''
result_count = 0
gip = pygeoip.GeoIP('GeoLIteCity.dat')
ip = self.ip_textbox.text()
try:
    ip = socket.gethostbyname(str(ip))
    message = "Host: %s Is Currently Available" % (str(ip))
except socket.error, e:
    message = "Host: %s Is Currently Unavailable" % (key, val)
result_count += 1
msg_box("SeArCh CoMpLeTe", "%d REsults Were Found For %s"
% (result_count, str(ip))
except Exception, e:   <------- Error
msg_box("", str(e))
msg_box("Search Complete", "No Results Were Found For %s" % (str(ip))
return 

错误:

File "pygeo_ip.py", line 142
    except Exception, e:
         ^
SyntaxError: invalid syntax

最佳答案

很确定(没有测试任何东西)你的问题是错过了最后一个右括号

行应为:

msg_box("SeArCh CoMpLeTe", "%d REsults Were Found For %s" % (result_count, str(ip)) )

关于python - 如何在 Linux 上修复 Python 中的 Except 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54101228/

相关文章:

python - VS Code 终端中的光标错误

linux - 从linux redhat访问windows主机上的svn存储库

linux - shell脚本中的su命令

linux - 了解 Docker Macvlan 网络

python - python 中的 "reduce"函数在 "namedtuple"上不起作用?

python - Python 中的 "result.status_code == 200"是什么意思?

python - 替换大于 Pandas 数据框中数字的值

python - 如何更改 seaborn 联合图中的十六进制大小? (六边形本身,而不是垃圾箱)

linux - 如何使用与我在 cron 作业中使用的环境相同的环境?

c++ - 为什么这个 write() 操作只写一行