Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unsupported type for timedelta minutes component: NoneType #548

Open
shuklashashank opened this issue Sep 8, 2020 · 3 comments
Open

unsupported type for timedelta minutes component: NoneType #548

shuklashashank opened this issue Sep 8, 2020 · 3 comments

Comments

@shuklashashank
Copy link

shuklashashank commented Sep 8, 2020

Initially, it ran well but when I retry to run it, it gives an error in gsuite-exporter.

sync_all(
credentials_path="cerd.json",
admin_user='admin@domain.com',
api='reports_v1',
applications=['login', 'drive', 'token'],
project_id='',
exporter_cls='stackdriver_exporter.StackdriverExporter'
)

below error:

/gsuite_exporter/cli.py in sync_all(admin_user, api, applications, project_id, exporter_cls, credentials_path, offset)
70 start_time = None
71 else:
---> 72 start_time = (parser.parse(last_ts) - timedelta(minutes=offset)).isoformat()
73 exporter_dest = exporter.get_destination(app)
74 logger.info(
TypeError: unsupported type for timedelta minutes component: NoneType

@agold-rh
Copy link
Contributor

@ocervell Do you have any input on this, or should this be closed as stale?

@i2TIC
Copy link

i2TIC commented Mar 8, 2023

I am experiencing the same issue. I have deployed the cloudfunction Python3.7 on GCP with the following code:
main.py

#!/usr/bin/env python3
import base64
import json
from gsuite_exporter.cli import sync_all


def run(data, context):

    # Decode Data From Pubsub Message
    name = base64.b64decode(data['data']).decode('utf-8')

    # Load Data in JSON
    dictionary = json.loads(name)

    # Parse JSON to Set Variables
    project_id = dictionary['PROJECT_ID']
    gsuite_admin_user = dictionary['GSUITE_ADMIN_USER']

    # Run Log Sync
    sync_all(
            admin_user=gsuite_admin_user,
            api='reports_v1',
            applications=['login', 'admin', 'drive', 'mobile', 'token'],
            project_id=project_id,
            exporter_cls='stackdriver_exporter.StackdriverExporter'
        )

requirements.txt

boto3
gsuite_exporter==0.0.4

I get the same error

Exception on /_ah/push-handlers/pubsub/projects/ms--siem--pro--f850/topics/gsuite-admin-logs-topic-trigger [POST]
Traceback (most recent call last):
  File "/layers/google.python.pip/pip/lib/python3.7/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/layers/google.python.pip/pip/lib/python3.7/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/layers/google.python.pip/pip/lib/python3.7/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/layers/google.python.pip/pip/lib/python3.7/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/layers/google.python.pip/pip/lib/python3.7/site-packages/functions_framework/__init__.py", line 171, in view_func
    function(data, context)
  File "/workspace/main.py", line 40, in run
    exporter_cls='stackdriver_exporter.StackdriverExporter'
  File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gsuite_exporter/cli.py", line 72, in sync_all
    start_time = (parser.parse(last_ts) - timedelta(minutes=offset)).isoformat()
TypeError: unsupported type for timedelta minutes component: NoneType

It worked on the first run but then is started to give this error, it seems that is failing on the step where it checks the timestamp of the logs to avoid duplicated entries

I have been looking at the code and on cli.py on the definition I can see that there is a argument name offset which by default set to None. This was causing the error to me. It says on a comment on the code that the argument offset is a str but when I set it as str if failt so I endup setting up as an int and it worket.

I didn't see this argument because I was following the next guide from terraform which should be updated otherwise the module can not be used correctly.

https://registry.terraform.io/modules/terraform-google-modules/gsuite-export/google/latest/examples/cloud_function

@agold-rh
Copy link
Contributor

agold-rh commented Mar 8, 2023

@matthewmarr Do you have any input on this?

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

No branches or pull requests

3 participants