8000 Deploying Cloud Function gives error: MissingTargetException · Issue #157 · GoogleCloudPlatform/functions-framework-python · GitHub
[go: up one dir, main page]

Skip to content

Deploying Cloud Function gives error: MissingTargetException #157

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

Closed
bhandari-nitin opened this issue Oct 19, 2021 · 9 comments
Closed

Deploying Cloud Function gives error: MissingTargetException #157

bhandari-nitin opened this issue Oct 19, 2021 · 9 comments
Assignees

Comments

@bhandari-nitin
Copy link

Hi there,

Deploying google cloud function with python3.8 runtime gives error:

MissingTargetException: File /workspace/main.py is expected to contain a function named main
.create_app ( /layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/__init__.py:259 )

Stacktrace

functions_framework.exceptions.MissingTargetException: File /workspace/main.py is expected to contain a function named main
at create_app (/layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/__init__.py:259)
at _cli (/layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/_cli.py:37)
at invoke (/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py:763)
at invoke (/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py:1404)
at main (/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py:1062)
at __call__ (/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py:1137)
at <module> (/layers/google.python.pip/pip/bin/functions-framework:8)

There is a main function within main.py that I am trying to deploy.

@di
Copy link
Member
di commented Oct 19, 2021

Hi, can you share your main.py file (or at least the signature of the function you're trying to deploy) as well as the command you're using to deploy?

@bhandari-nitin
Copy link
Author
bhandari-nitin commented Oct 19, 2021

I assume by signature of the function you mean the main function? I am using console GUI to deploy and not thru command line.

def main(request):
    print("In function: main")
    try:
        req_data = request.get_json(silent=True, force=True)
        result = req_data["queryResult"]

        queryText = result.get("queryText")
        session = req_data["session"]

        intent_id = result["intent"]["name"].split("intents/")[-1]
        intent_name = result["intent"]["displayName"]

        parameters = result["parameters"]
        oc_withinReq = result["outputContexts"]

        print("Received Request:\n\n {}\n\n".format(req_data))
        print(
            "Received Query Text: {} and Data-Type of Query Text: {}".format(
                queryText, type(queryText)
            )
        )

        print(
            "Intent Detected: {} with Intent ID: {}\n\n".format(intent_name, intent_id)
        )

        # If there is a response set in dialogflow
        # So, if you want to form a response from
        # webhook, don't set any response in dialogflow
        if "fulfillmentMessages" in result:
            print("Fulfillment Message found in df request")
            df_res = result["fulfillmentMessages"]
            out = fulfill_intent(
                intent_name,
                intent_id,
                session,
                parameters=parameters,
                oc_withinReq=oc_withinReq,
                df_res=df_res,
            )

        elif "fulfillmentText" in result:
            print(
                "Fulfillment Text Response found in df request, selecting response set in dialogflow.\n\n"
            )
            df_res = result["fulfillmentText"]

            out = fulfill_intent(
                intent_name,
                intent_id,
                session,
                parameters=parameters,
                oc_withinReq=oc_withinReq,
                df_res=df_res,
            )

        else:
            print("Within main function, no response set in dialogflow.\n\n")
            out = fulfill_intent(
                intent_name,
                intent_id,
                session,
                parameters=parameters,
                oc_withinReq=oc_withinReq,
            )


    except:
        print("Within main function, the following exception was caught: \n\n")
        print_exc()
        out = {
            "fulfillmentText": """I'm sorry, it looks like something's gone wrong, try saying something else,
                                      and we'll have someone fix this problem soon.""",
            # "outputContexts": output_contexts
        }

    return out

@di
Copy link
Member
di commented Oct 19, 2021

I created a new Python 3.8 function by pasting that into the UI at https://console.cloud.google.com/functions/add, changing the entrypoint from hello_world to main, and was able to successfully deploy it.

Any other details you can give us? Have you set any environment variables or otherwise changed the function configuration?

Can you go to the "Source" tab for the function and select "Download Zip" and upload it here?

@bhandari-nitin
Copy link
Author
bhandari-nitin commented Oct 19, 2021

@di I see, strange. I tried the same with only the code I shared and got same error.

Here are the details:

  1. Region: US-Central1
  2. Trigger: HTTP
  3. Runtime: Python3.8
  4. Memory Allocated: 256 MB
  5. Executed Function: main
  6. Authentication:

Zip file:
function-source.zip

@di
Copy link
Member
di commented Oct 19, 2021

Just to be clear, this error is happening on deployment, when you create the function, not when you call your function, correct?

Unfortunately I haven't been able to reproduce this, but any more details you can provide would be helpful.

@bhandari-nitin
Copy link
Author

correct, what more details I can provide that'd be helpful?

@di
Copy link
Member
di commented Oct 19, 2021

Instead of using the "inline editor" for source code, can you try a new function with the "ZIP upload" option and upload the zip file you included in #157 (comment)?

Can you confirm that the "Entry point" field says main with no extra spaces?

It should look like this (you'll need to specify or create a GCS bucket for the 'stage bucket'):

image

image

@bhandari-nitin
Copy link
Author

So, deploying through zip upload worked but another weird thing is under Authentication, it should say allow unautheicated bc that's what I selected but it is blank.

Also, tried using inline editor making sure the entry point is main without any whitespace character/s and it still failed.

@grant grant self-assigned this Jun 10, 2022
@grant
Copy link
Contributor
grant commented Jun 10, 2022

Reading through this thread... it seems like we've figured out a way to deploy successfully. Not sure if there is an issue with the Functions Framework.

I'm going to close this, but if the issue is still persisting, please open a new issue and link this issue in the description.

@grant grant closed this as completed Jun 10, 2022
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
0