Skip to content

Handle protobuf encoding/decoding errors during uploads and album creation#43

Open
xob0t wants to merge 1 commit intomainfrom
proto-decode-error-handling
Open

Handle protobuf encoding/decoding errors during uploads and album creation#43
xob0t wants to merge 1 commit intomainfrom
proto-decode-error-handling

Conversation

@xob0t
Copy link
Owner

@xob0t xob0t commented Nov 11, 2025

fixes #42

@Cohinem
Copy link

Cohinem commented Nov 13, 2025

Trying out the branch with the fix still gets me an error.
Additional Note: the image is still in the account. upon deleting the image and reuploading it again the problem for only that particular image is fixed. but as you know that is highly inconvenient for mass upload and doesn't fix the underlying problem.

I guess Google photos assigns new media keys for the image. so automatically reuploading can also be a roundabout solution?

expand log output

# gpmc 'omitted.jpg' --album "testp" --progress --log-level DEBUG


21:33:13 INFO     User: omitted@gmail.com                                                            client.py:65
         INFO     Language: en_US                                                                          client.py:66
         DEBUG    Starting new HTTPS connection (1): android.googleapis.com:443                  connectionpool.py:1049
21:33:14 DEBUG    https://android.googleapis.com:443 "POST /auth HTTP/1.1" 200 None               connectionpool.py:544
         DEBUG    Starting new HTTPS connection (1): photosdata-pa.googleapis.com:443            connectionpool.py:1049
21:33:15 DEBUG    https://photosdata-pa.googleapis.com:443 "POST                                  connectionpool.py:544
                  /6439526231001122323/5084921699730810217 HTTP/1.1" 200 None
         DEBUG    Could not decode a buffer for field (['1']) as a message: Encountered error       length_delim.py:591
                  decoding field 9: Got unknown wire type: 6
         DEBUG    Could not decode a buffer for field (['1']) as a message: Encountered error       length_delim.py:591
                  decoding field 6: Field 6 has mistmatched wiretypes. Previous: 1 Now: 7
         DEBUG    Could not decode a buffer for field (['3']) as a message: Encountered error       length_delim.py:591
                  decoding field 6: Got unknown wire type: 7
Files processed:   1/1 0:00:01 Errors: 0
         ERROR    Failed to encode create_album request for album 'testp' with 1 media items                 api.py:448
         DEBUG    Proto body: {'1': 'testp', '2': 1763058795, '3': 1, '4': [{'1': {'1': {'8':                api.py:449
                  6145809786699067718, '5': 1229019448, '14': 3486153685529674595, '6': 761869145, '12':
                  8737883117062341983, '9': 1900754516, '7': 101}}}], '6': {}, '7': {'1': 3}, '8': {'3':
                  'Pixel XL', '4': 'Google', '5': 28}}
         DEBUG    Media keys: [{'8': 6145809786699067718, '5': 1229019448, '14': 3486153685529674595, '6':   api.py:450
                  761869145, '12': 8737883117062341983, '9': 1900754516, '7': 101}]
         ERROR    Protobuf error while adding items to album 'testp': Failed to encode create_album       client.py:580
                  request: Encountered error encoding field 4->1->1: Error encoding string to message:
                  {'8': 6145809786699067718, '5': 1229019448, '14': 3486153685529674595, '6': 761869145,
                  '12': 8737883117062341983, '9': 1900754516, '7': 101}
         INFO     Batch of 1 items skipped. Media keys (first 3): [{'8': 6145809786699067718, '5':        client.py:581
                  1229019448, '14': 3486153685529674595, '6': 761869145, '12': 8737883117062341983, '9':
                  1900754516, '7': 101}]
Adding items to album testp: ⠋ 0/1 0:00:00
Traceback (most recent call last):
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/types/length_delim.py", line 59, in encode_string
    value = six.ensure_text(value)
            ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.12/site-packages/six.py", line 960, in ensure_text
    raise TypeError("not expecting type '%s'" % type(s))
TypeError: not expecting type '<class 'dict'>'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/root/.local/lib/python3.12/site-packages/gpmc/api.py", line 446, in create_album
    serialized_data = encode_message(proto_body, message_types.CREATE_ALBUM)  # type: ignore
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/api.py", line 152, in encode_message
    blackboxprotobuf.lib.types.length_delim.encode_message(
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/types/length_delim.py", line 165, in encode_message
    field_number, outputs = _encode_message_field(
                            ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/types/length_delim.py", line 275, in _encode_message_field
    six.reraise(*sys.exc_info())
  File "/root/.local/lib/python3.12/site-packages/six.py", line 724, in reraise
    raise value
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/types/length_delim.py", line 269, in _encode_message_field
    outputs.append(tag + field_encoder(repeated))
                         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/types/length_delim.py", line 241, in <lambda>
    field_encoder = lambda data: encode_lendelim_message(
                                 ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/types/length_delim.py", line 634, in encode_lendelim_message
    message_out = encode_message(
                  ^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/types/length_delim.py", line 165, in encode_message
    field_number, outputs = _encode_message_field(
                            ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/types/length_delim.py", line 275, in _encode_message_field
    six.reraise(*sys.exc_info())
  File "/root/.local/lib/python3.12/site-packages/six.py", line 724, in reraise
    raise value
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/types/length_delim.py", line 271, in _encode_message_field
    outputs.append(tag + field_encoder(value))
                         ^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/types/length_delim.py", line 241, in <lambda>
    field_encoder = lambda data: encode_lendelim_message(
                                 ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/types/length_delim.py", line 634, in encode_lendelim_message
    message_out = encode_message(
                  ^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/types/length_delim.py", line 165, in encode_message
    field_number, outputs = _encode_message_field(
                            ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/types/length_delim.py", line 275, in _encode_message_field
    six.reraise(*sys.exc_info())
  File "/root/.local/lib/python3.12/site-packages/six.py", line 724, in reraise
    raise value
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/types/length_delim.py", line 271, in _encode_message_field
    outputs.append(tag + field_encoder(value))
                         ^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.12/site-packages/blackboxprotobuf/lib/types/length_delim.py", line 61, in encode_string
    six.raise_from(
  File "<string>", line 3, in raise_from
blackboxprotobuf.lib.exceptions.EncoderException: Encountered error encoding field 4->1->1: Error encoding string to message: {'8': 6145809786699067718, '5': 1229019448, '14': 3486153685529674595, '6': 761869145, '12': 8737883117062341983, '9': 1900754516, '7': 101}

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/root/.local/bin/gpmc", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/root/.local/lib/python3.12/site-packages/gpmc/cli.py", line 53, in main
    output = client.upload(
             ^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.12/site-packages/gpmc/client.py", line 313, in upload
    self._handle_album_creation(results, album_name, show_progress)
  File "/root/.local/lib/python3.12/site-packages/gpmc/client.py", line 183, in _handle_album_creation
    self.add_to_album(media_keys, album_name, show_progress=show_progress)
  File "/root/.local/lib/python3.12/site-packages/gpmc/client.py", line 574, in add_to_album
    current_album_key = self.api.create_album(album_name=current_album_name, media_keys=batch)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/lib/python3.12/site-packages/gpmc/api.py", line 451, in create_album
    raise ProtobufEncodeError(f"Failed to encode create_album request: {e}") from e
gpmc.exceptions.ProtobufEncodeError: Failed to encode create_album request: Encountered error encoding field 4->1->1: Error encoding string to message: {'8': 6145809786699067718, '5': 1229019448, '14': 3486153685529674595, '6': 761869145, '12': 8737883117062341983, '9': 1900754516, '7': 101}


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

Successfully merging this pull request may close these issues.

Error uploading some images

2 participants