[Python] Google Cloud Scheduler cannot find Python Script Cloud Run jobname

Discussão em 'Python' iniciado por Stack, Agosto 6, 2025.

  1. Stack

    Stack Membro Participativo

    When I run the script as a cloud function it can find the job name, but when I run it in cloud run jobs it can't find the job name.

    What exactly am I doing wrong?

    httpRequest: {1}
    insertId: "8vr1cwfi77fef"
    jsonPayload: {
    @type: "type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished"
    jobName: "projects/api-data-pod/locations/us-central1/jobs/mouse-recording"
    status: "NOT_FOUND"
    targetType: "HTTP"
    url: "https://us-central1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/api-data-pod/jobs/mouseflowrecording:run"
    }
    logName: "projects/api-data-pod/logs/cloudscheduler.googleapis.com%2Fexecutions"
    receiveTimestamp: "2022-08-02T11:54:04.664184360Z"
    resource: {
    labels: {3}
    type: "cloud_scheduler_job"
    }
    severity: "ERROR"
    timestamp: "2022-08-02T11:54:04.664184360Z"
    }


    import requests

    import json

    import pandas as pd

    import pandas_gbq

    from google.cloud import bigquery

    from requests.auth import HTTPBasicAuth

    #import schedule

    #import time

    def rec(request):
    r = requests.get("https://api-eu.mouseflow.com/websites/e768ed54-c09b-48dc-bf49-beda12697013/recordings",

    auth=HTTPBasicAuth("*************", "********************"))

    if r.status_code == 200:

    parsed = json.loads(r.text)

    print(json.dumps(parsed['recordings'], indent=4, sort_keys=True))

    df = pd.DataFrame.from_records(parsed['recordings'])

    #print(df.dtypes)


    #df.to_csv('mousedata3.csv')#
    try:
    temp_csv_string = df.to_csv(sep=";", index=False)
    temp_csv_string_IO = StringIO(temp_csv_string)
    # create new dataframe from string variable
    new_df = pd.read_csv(temp_csv_string_IO, sep=";")
    # this new df can be uploaded to BQ with no issues
    new_df.to_gbq('Mouseflow.Mouseflow_Recording', if_exists='replace', project_id='api-data-pod')
    return f'Successful'
    except Exception as err:
    return f'Upload to BigQuery failed: {err}'
    else:
    return f'API request error occurred: Status code {r.status_code}'
    rec(requests.request)


    The only difference with the cloud function code is that I don't have an end to function as it is not needed. So this is not at the end of my code: rec(requests.request).

    Continue reading...

Compartilhe esta Página