I found this thread when searching for the same message, but my solution
was entirely different. It turned out that I was trying to update a client
to use a slightly modified proto file, and I was making a call that was
assigning to a field that no longer existed. But the error message here (
TypeError:
Message must be initialized with a dict) is completely misleading -- the
real message should have been "unknown argument" or "unknown field" or
something ....
On Sunday, June 11, 2023 at 12:38:42 AM UTC-4 Tony Piazza wrote:
> The problem had to do with the Date and Timestamp fields. The problem was
> solved by converting them to int64.
>
> On Saturday, June 10, 2023 at 10:56:36 PM UTC-5 Tony Piazza wrote:
>
>> My current task requires me to use the BigQuery Storage Write API. I have
>> created a .proto file and was able to use protoc to generate a Python
>> message class. I am seeing this exception when creating an instance of that
>> class:
>>
>> *TypeError: Message must be initialized with a dict:
>> combocurve.Measurement*
>>
>> *File "/google/api_core/grpc_helpers.py", line 162, in
>> error_remapped_callable*
>>
>> Here is my .proto file:
>>
>> syntax = "proto2";
>>
>> package combocurve;
>>
>> import "google/protobuf/timestamp.proto";
>> import "google/type/date.proto";
>>
>> message Measurement {
>> required string device_id = 1;
>> required google.type.Date last_service_date = 2;
>> optional double temperature = 3;
>> optional double pressure = 4;
>> optional google.protobuf.Timestamp created_at = 5;
>> }
>>
>> Here is the code that is raising the exception:
>>
>> measurement = Measurement(
>> device_id='ABC123',
>> last_service_date=date_pb2.Date(
>> year=last_service_date.year,
>> month=last_service_date.month,
>> day=last_service_date.day),
>> temperature=10.0,
>> pressure=20.0,
>> created_at=int(created_at.timestamp() * 1e6)
>> )
>>
>> Please let me know if you have any ideas as to what is causing this
>> exception.
>>
>> Thanks in advance for your help!
>>
>> -Tony
>>
>
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/protobuf/cf2858c3-fd19-491f-a44b-ad336d67b8a6n%40googlegroups.com.