Hi I am trying to write a python script that does exactly what the following command does:
gcloud logging read "logName=projects/[project_name]/logs/[id]"
so when i run that command from the cli it does not give me any error, it outputs the logs as expected.
however when i run my python script:
import argparse
import datetime
import os
import sys
from pprint import pprint
from google.cloud import bigquery
from google.cloud import logging
assert "GOOGLE_APPLICATION_CREDENTIALS" in os.environ
def main():
client = logging.Client()
log_name = 'log_id'
logger = client.logger(log_name)
for entry in logger.list_entries():
print(entry.payload)
if __name__ == "__main__":
main()
I get the error: google.api_core.exceptions.PermissionDenied: 403 The caller does not have permission
Im not sure what to do here, since the command line runs, i clearly have permission. any thoughts would be greatly appreciated
I see that you are trying to read and show your logs from Cloud Logging using Python.
From the error code you got:
error: google.api_core.exceptions.PermissionDenied: 403
I think this comes from an authentication problem. I would like to share these documents with you: the Python quickstart to write, read, delete, and export log entries [1]; and authentication on GCE instances [2].
[1] https://cloud.google.com/logging/docs/quickstart-python#linux
[2] https://googleapis.dev/python/google-api-core/latest/auth.html#using-google-compute-engine
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.