Python giving KeyError for inexplicable reason

517 Views Asked by At

I'm getting this error which I haven't been able to figure out for a long time in 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

I'm calling the function get_pcapng_section_header() which is in another file that I imported like so:

from easy_parse.pcapng import *

Here is how I'm calling the module from my main function:

#  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)

Here's a snippet of the pcapng module:

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

There are 0 best solutions below