for part in message['payload']['parts']:
    if part['filename']:
        if 'data' in part['body']:
            data = part['body']['data']
else:
    att_id = part['body']['attachmentId']
att = service.users().messages().attachments().get(userId=user_id,
    messageId=msg_id, id=att_id).execute()
data = att['data']
file_data = base64.urlsafe_b64decode(data.encode('UTF-8'))
Загрузка вложений из gmail с помощью Gmail API