pickle.PicklingError: Can't pickle<br>:...

3460 ワード

python-nmap 0がインストール.14後、簡単なテストの実行に失敗しました.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "D:\opt\Python27\lib\multiprocessing\forking.py", line 373, in main
    prepare(preparation_data)
  File "D:\opt\Python27\lib\multiprocessing\forking.py", line 488, in prepare
    '__parents_main__', file, path_name, etc
  File "E:\Workspace\scanner_01.py", line 13, in <module>
    nma.scan(hosts='192.168.18.0/24', arguments='-sP')
  File "D:\opt\Python27\lib\site-packages
map
map.py", line 417, in scan self._process.start() File "D:\opt\Python27\lib\multiprocessing\process.py", line 130, in start self._popen = Popen(self) File "D:\opt\Python27\lib\multiprocessing\forking.py", line 271, in __init__ dump(process_obj, to_child, HIGHEST_PROTOCOL) File "D:\opt\Python27\lib\multiprocessing\forking.py", line 193, in dump ForkingPickler(file, protocol).dump(obj) File "D:\opt\Python27\lib\pickle.py", line 224, in dump self.save(obj) File "D:\opt\Python27\lib\pickle.py", line 331, in save self.save_reduce(obj=obj, *rv) File "D:\opt\Python27\lib\pickle.py", line 419, in save_reduce save(state) File "D:\opt\Python27\lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "D:\opt\Python27\lib\pickle.py", line 649, in save_dict self._batch_setitems(obj.iteritems()) File "D:\opt\Python27\lib\pickle.py", line 681, in _batch_setitems save(v) File "D:\opt\Python27\lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "D:\opt\Python27\lib\pickle.py", line 747, in save_global (obj, module, name)) pickle.PicklingError: Can't pickle <function scan_progressive at 0x01C255B0>: it 's not found as nmap.nmap.scan_progressive

コードは次のとおりです.
import nmap
nma = nmap.PortScannerAsync()

def callback_result(host, scan_result):
    print '------------------'
    print host, scan_result

nma.scan(hosts='192.168.18.0/24', arguments='-sP')

while nma.still_scanning():
    print("Waiting ...")
    nma.wait(2) 

最初はコードが間違っていると思っていたが、nmapインストールディレクトリのexampleを見つけた.py実行、同じエラーが発生しました.追跡を繰り返した結果、pickleで発見された.pyファイル745行にエラーが投げ出されました.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\opt\Python27\lib\site-packages
map
map.py", line 413, in scan target=self.scan_progressive, AttributeError: 'PortScannerAsync' object has no attribute 'scan_progressive'

それからnmapのソースnmapを読みます.py、やっと402行で、方法scan_progressiveはscanメソッドの内部に定義され、pickleが失敗した.
解決方法:
メソッドScan_progressiveは外に定義し、nmap.py 413行から
target=scan_progressive,
から次のように変更されました.
target=self.progressive,
でいいです.
総括:木が他の影响があることを知らないで、しかし1つの结论を出して、他の人のもの、信用を尽くすことができなくて、钢は鉄で、试してやっと知っています...