【发布时间】:2015-02-07 21:54:45
【问题描述】:
我有一个 Python 初学者编码课程。我们正在使用的书是“为渗透测试人员编写更好的工具的编码”。在第二章中,我们开始创建 Python 脚本,我似乎无法弄清楚我应该从书中重新输入的这个脚本有什么问题。见下文。
import httplib, sys
if len(sys.argv) < 3:
sys.exit("Usage " + sys.argv[0] + " <hostname> <port>\n")
host = sys.argv[1]
port = sys.argv[2]
client = httplib.HTTPConnection(host,port)
client.request("GET","/")
resp = client.getresponse()
client.close()
if resp.status == 200:
print host + " : OK"
sys.exit()
print host + " : DOWN! (" + resp.status + " , " + resp.reason + ")"
运行代码后,我在第 20 行(最后一个打印行)出现错误:
selmer@ubuntu:~$ python /home/selmer/Desktop/scripts/arguments.py google.com 80
Traceback (most recent call last):
File "/home/selmer/Desktop/scripts/arguments.py", line 20, in <module>
print host + " : DOWN! (" + resp.status + " , " + resp.reason + ")"
TypeError: cannot concatenate 'str' and 'int' objects
所有代码都在带有 Konsole 的 VM 中的 Ubuntu 14.04 中运行,并在 Gedit 中创建。任何帮助将不胜感激!
【问题讨论】:
标签: python typeerror traceback