Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 CEF Adapater struct.unpack requires bytes-like object #14

Open
Amorik opened this issue Mar 4, 2021 · 0 comments
Open

Python3 CEF Adapater struct.unpack requires bytes-like object #14

Amorik opened this issue Mar 4, 2021 · 0 comments

Comments

@Amorik
Copy link

Amorik commented Mar 4, 2021

Use of the python3 branch and the CEF codec results in the following error:

Traceback (most recent call last):
  File "/opt/eNcore/estreamer/baseproc.py", line 208, in receiveInput
    self.onReceive( item )
  File "/opt/eNcore/estreamer/baseproc.py", line 313, in onReceive
    self.onEvent( item )
  File "/opt/eNcore/estreamer/pipeline.py", line 397, in onEvent
    data = transform( item, self.settings )
  File "/opt/eNcore/estreamer/pipeline.py", line 205, in transform
    output = adapters[ index ].dumps( event['record'] )
  File "/opt/eNcore/estreamer/adapters/cef.py", line 820, in dumps
    return cefAdapter.dumps()
  File "/opt/eNcore/estreamer/adapters/cef.py", line 810, in dumps
    self.__convert()
  File "/opt/eNcore/estreamer/adapters/cef.py", line 735, in __convert
    self.output[target] = function( self.record )
  File "/opt/eNcore/estreamer/adapters/cef.py", line 147, in <lambda>
    'cs1': lambda rec: __packetData( rec['packetData'] )
  File "/opt/eNcore/estreamer/adapters/cef.py", line 115, in __packetData
    payload = packet.getPayloadAsAscii()
  File "/opt/eNcore/estreamer/common/packet.py", line 95, in getPayloadAsAscii
    asciiPayload = self.getPayloadAsBytes().decode( 'ascii', 'ignore' )
  File "/opt/eNcore/estreamer/common/packet.py", line 85, in getPayloadAsBytes
    self.__getLayer3HeaderLength() +
  File "/opt/eNcore/estreamer/common/packet.py", line 55, in __getLayer3HeaderLength
    self.__getNyble( ipOffsetNyble ) *
  File "/opt/eNcore/estreamer/common/packet.py", line 41, in __getNyble
    byte = struct.unpack( '>B', self.data[byteIndex] )[0]
TypeError: a bytes-like object is required, not 'int'

Python2 handled the conversion to bytes when using struct.unpack, Python3 does not.

byte = struct.unpack( '>B', self.data[byteIndex] )[0]

Can be resolved by updating line to include bytes conversion:

byte = struct.unpack( '>B', bytes(self.data[byteIndex]) )[0] 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant