Я пытаюсь выполнить простой анализ сообщения protobuf POST
. Запускаю Python 2.7, просто пытаюсь вывести понятную человеку строку сообщения в файл. Однако, когда я пытаюсь это сделать, выдает _DecodeError('Truncated message.')
Мой код:
@app.route('/<uid>', methods=['GET', 'POST'])
def handler(uid, event=None, context=None):
if request.method == 'POST':
raw_data = request.get_data()
myfile = open('data.txt', 'w+')
devices_frame = DevicesFrame_pb2.DevicesFrame()
devices_frame.ParseFromString(str(raw_data))
myfile.write(str(devices_frame))
myfile.close()
return 200
И ошибка:
Traceback (most recent call last):
File "c:\python27\lib\site-packages\flask\app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "c:\python27\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "c:\python27\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "c:\python27\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "c:\python27\lib\site-packages\flask\app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "main.py", line 427, in handler
devices_frame.ParseFromString(str(raw_data))
File "c:\python27\lib\site-packages\google\protobuf\message.py", line 185, in ParseFromString
self.MergeFromString(serialized)
File "c:\python27\lib\site-packages\google\protobuf\internal\python_message.py", line 1083, in MergeFromString
if self._InternalParse(serialized, 0, length) != length:
File "c:\python27\lib\site-packages\google\protobuf\internal\python_message.py", line 1109, in InternalParse
new_pos = local_SkipField(buffer, new_pos, end, tag_bytes)
File "c:\python27\lib\site-packages\google\protobuf\internal\decoder.py", line 850, in SkipField
return WIRETYPE_TO_SKIPPER[wire_type](buffer, pos, end)
File "c:\python27\lib\site-packages\google\protobuf\internal\decoder.py", line 782, in _SkipFixed64
raise _DecodeError('Truncated message.')
Редактировать: По какой-то причине он теперь выбрасывает Tag had invalid wire type
.