Python дает KeyError по необъяснимой причине

Я получаю эту ошибку, которую я долго не мог понять в python:

Traceback (most recent call last):  
  File "st2110_parse_KB.py", line 173, in <module>  
    section_header = get_pcapng_section_header(input_pcapng_file)  
  File "Z:\easy_parse\pcapng.py", line 190, in get_pcapng_section_header  
    assert(block_types[block_type] == "Section Header Block"), \  
KeyError: 3569595041L

Я вызываю функцию get_pcapng_section_header() который находится в другом файле, который я импортировал так:

from easy_parse.pcapng import *

Вот как я вызываю модуль из своей основной функции:

#  input_pcapng_file = open("filename.pcap",'rb')

if filename:
  print "file works"
else:
  print "doesnt"

port_filter_str + '.payload'


print "its fine here"

section_header = get_pcapng_section_header(input_pcapng_file)

Вот фрагмент модуля pcapng:

def get_pcapng_section_header(input_file):

  # The Section Header Block is special because it defines the endian.
  # Because of this get_pcapng_block (which requires endian) won't be used
  # until the endian is determined.

  section_header_block_file_position = input_file.tell()

  # The endian doesn't matter for the Section Header Block's Block Type.
  block_type = bytes_to_int(input_file.read(4), "big")

  assert(block_types[block_type] == "Section Header Block"), \
      "Block Type %d is not Section Header Block at 0x%08x" % (block_type, section_header_block_file_position)

  # Skip the length for now.
  input_file.read(4)

0 ответов

Другие вопросы по тегам