Ask Your Question

Rosbag read error

asked 2019-09-21 08:37:05 -0600

panand2000 gravatar image

updated 2019-09-21 11:21:02 -0600

gvdhoorn gravatar image


I have a rosbag with two topics. when i use rosbag play there were no errors. however i use bag.read_messages() it gives the following error. I am new to ros can help me solving this issue. ros reindex and filter also gives the smae error.

 Traceback (most recent call last):
  File "", line 11, in <module>
    for topic, msg, t in bag1.read_messages(topics=['gsmsg']):
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rosbag/", line 2679, in read_messages
    yield self.seek_and_read_message_data_record((entry.chunk_pos, entry.offset), raw, return_connection_header)
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rosbag/", line 2826, in seek_and_read_message_data_record
    header = _read_header(f)
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rosbag/", line 2001, in _read_header
    return _build_header_from_str(header, req_op)
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rosbag/", line 2015, in _build_header_from_str
    raise ROSBagFormatException('Error reading header field: expected %d bytes, read %d' % (size, len(header)))
rosbag.bag.ROSBagFormatException: Error reading header field: expected 38 bytes, read 34
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-09-21 16:58:39 -0600

Jari gravatar image

I'm going to guess the bag file was made in an older version of ROS. If it wasn't melodic then the message definitions could have changed, in which case see this link for what to do (you can probably get away with rosbag check and rosbag fix)

edit flag offensive delete link more


Thanks for the reply. Yes, the bag file is generated in ros kinetic. I tried rosbag fix and check. but both gave same error. even I tried in ros kinetic it also gave same error. Can you pls give some example for generating rules.

panand2000 gravatar image panand2000  ( 2019-09-22 01:19:35 -0600 )edit

What are the message types?

Jari gravatar image Jari  ( 2019-09-25 09:27:06 -0600 )edit

messages are std_msgs/String type

rosbag info data16_58_16.bag path: data16_58_16.bag version: 2.0 duration: 3:46s (226s) start: Sep 13 2019 16:58:17.36 (1568357897.36) end: Sep 13 2019 17:02:04.16 (1568358124.16) size: 295.5 KB messages: 2286 compression: none [1/1 chunks] types: std_msgs/String [992ce8a1687cec8c8bd883ec73ca41d1] topics: gsmsg 2059 msgs : std_msgs/String phenommsg 227 msgs : std_msgs/String

Also while playing this bag while says to wait 0.2 s

rosbag play data16_586.bag Waiting 0.2 seconds after advertising topics... done.

Hit space to toggle paused, or 's' to step. [RUNNING] Bag Time: 1568357897.357594 Duration: 0.000000 / 226.807380 [RUNNING] Bag Time: 1568357897.357795 Duration: 0.000201 / 226.807380 [RUNNING] Bag Time: 1568357897.458035 Duration: 0.100441 /

panand2000 gravatar image panand2000  ( 2019-09-25 23:51:50 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2019-09-21 08:29:30 -0600

Seen: 680 times

Last updated: Sep 21 '19