Python: Integer Out Of Range For 'l' Format Code
In python, the code is the following envimsg = struct.pack('!LHL', 1, 0, int(jsonmsg['flow_id'], 16)) + \ struct.pack('!HQH', 1, int(flow['src id'],16), 0) + \
Solution 1:
Even in the error line is pointing to this line, the error is not located there. Executing this instruction in the Python interpreter produces no error:
importstructstruct.pack("!H", 0)
>>> '\x00\x00'
This makes sense, as the error is complaining on the 'L' format code, so the error will be located in the ones which use this format.
Given that 'L' is used for unsigned long, and the message complains on being out of range, the error is because one (or more) of the variables used are negative, producing the out of range for unsigned long.
This can be verified in the Python interpreter:
importstructstruct.pack("!HHHLL", 1, 2, 3, 4, 5)
>>> '\x00\x01\x00\x02\x00\x03\x00\x00\x00\x04\x00\x00\x00\x05'struct.pack("!HHHLL", 1, 2, 3, -4, 5)
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: integer out of rangefor'L' format code
Solution 2:
Most likely the problem is in the value of one of these:
jsonmsg["flow_id"]
jsonmsg["app_src_ip"]
jsonmsg["app_dst_ip"]
Post a Comment for "Python: Integer Out Of Range For 'l' Format Code"