我試圖呼叫connect()
函數parse_ip()
,它將通過網頁搜索輸入IP來查找匹配項。對列表THREAT
的每個元素調用 Connect
函數。 這裏是我的代碼:HTTP連接解析失敗
def connect(url):
sessions = requests.Session()
print "Connecting with", url
try:
r = sessions.get(url,
headers = create_basic_headers(),
proxies = {'http': HTTP_PROXY, 'https': HTTPS_PROXY})
return r
except:
sys.stdout.write('[!] Could not connect to: %s\n' % url)
def parse(ip):
counter = 0
ioc_list = []
for filename, source in THREAT.iteritems():
c = connect(source)
for line in c:
if line.startswith("/") or line.startswith('\n') or line.startswith("#"):
pass
else:
counter += 1
d = 0
while d < len(ip):
if ip[d] in line:
print ip[d], source
d +=1
在運行腳本,解析頁面連接失敗和atlast我收到以下錯誤:
[!] Could not connect to: http://... for line in c: TypeError: 'NoneType' object is not iterable
誰能幫我在盤算什麼錯誤在這。
爲什麼不嘗試抓取並在'connect()'中打印異常? – mhawke
暫時刪除try/except塊來顯示堆棧跟蹤,這比你在那裏有更多的幫助。當你終於弄明白的時候,趕上一個特定的異常並處理它。不要按照您目前的方式捕捉所有異常:這很難調試問題。 –