0

I'm getting a type error when trying to run the following code as a google cloud function.

It's an altered version of: https://github.com/OWOX/BigQuery-integrations/tree/master/intercom

Where I've hardcoded the post parameters and triggering the function as a sub/pub in google cloud.

I've altered the main function intercom to not take in the post request that was the original trigger for the function (please see above github) and have instead hardcoded the parameters that was otherwise in the post.

payload = {
        "intercom": {
            "accessToken": "accesstoken",
            "entities": [
                "users",
                "companies",
                "contacts",
                "admins",
                "conversations",
                "teams",
                "tags",
                "segments"
            ]
        },
        "bq": {
            "project_id": "project_id",
            "dataset_id": "dataset_id",
            "location": "US"
        }
    }

def intercom():
    try:
        # get POST data from Flask.request object
        intercom_configuration = payload["intercom"]
        bq_configuration = payload["bq"]

        if not bq_configuration.get("location"):
            bq_configuration["location"] = "US"

    except Exception as error:
        print("An error occured with POST request data.")
        print(str(error))

        raise SystemExit

    # go to writable directory
    os.chdir(gc_write_dir)

    # getting data from intercom
    for entity in intercom_configuration["entities"]:

        if entity in ("companies", "users"):
            try:
                json_file = get_intercom_data_scroll(intercom_configuration, entity)

                # upload the file to BigQuery
                try:
                    load_to_gbq(json_file, bq_configuration, entity)
                except Exception as error:
                    print("An error occured trying to upload file to Google BigQuery.")
                    print(str(error))


            except Exception as error:
                print("An error occured trying to get data from intercom.")
                print(str(error))
        else:
            try:
                json_file = get_intercom_data(intercom_configuration, entity)

                # upload the file to BigQuery
                try:
                    load_to_gbq(json_file, bq_configuration, entity)
                except Exception as error:
                    print("An error occured trying to upload file to Google BigQuery.")
                    print(str(error))


            except Exception as error:
                print("An error occured trying to get data from intercom.")
                print(str(error))

    print("All tasks have been completed.")

There's a lot more to the code, but it should ultimately fetch the data from the Intercom API and send it to google big query.

traceback:
"Traceback (most recent call last):
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 383, in run_background_function
    _function_handler.invoke_user_function(event_object)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 217, in invoke_user_function
    return call_user_function(request_or_event)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 214, in call_user_function
    event_context.Context(**request_or_event.context))
TypeError: intercom() takes 0 positional argument but 2 were given
}
Dustin Ingram
  • 20,502
  • 7
  • 59
  • 82
  • You did not include the code that calls intercom(). – John Hanley Apr 15 '19 at 18:19
  • Hi John, It's being called from the google cloud platform using a cloud function. This essentially just means that it's calling intercom without any parameters. – Lucas Castenborg Apr 15 '19 at 20:19
  • 1
    Possible duplicate of [Google Cloud Functions - Why are two positional arguments passed into my function by GCF?](https://stackoverflow.com/questions/52657172/google-cloud-functions-why-are-two-positional-arguments-passed-into-my-functio) – Dustin Ingram Apr 17 '19 at 20:02

0 Answers0