+2 votes

Hey All,

I am trying to execute a .py file from a .gd script with the following code:

var global_dir_path = ProjectSettings.globalize_path("res://OAuth2.0")

var ERR = OS.execute("python", [global_dir_path + "/get_credentials.py"], true)
    if ERR == OK:
        get_token_from_JSON()
    else:
        push_error("ERROR EXECUTING 'get_credentials.py' WITH ERROR CODE: %s"%ERR)

I am getting an ERR == 1, which is "FAILED = 1 --- Generic error" from the Godot Docs.

I know for a fact that the script works when run from my IDE and the command line, and that the path to the .py script is correct. I am wondering if there are some permissions I am violating or something?

The .py script accesses scripts in its local directory. do you think that is the issue somehow?

Godot version 3.3.2
in Engine by (594 points)

Are you able to execute the exact same command in cmd/terminal?

Yes this works in the terminal. I think it might have something to do with the fact that I have python as an alias for python3.9 in my terminal.

1 Answer

+1 vote
Best answer

The problem was solved by using the absolute path for the python executable for some reason. On a mac, you can find this by doing where python3 in the terminal. I did where python3.9 because I knew I wanted that version to be used.

I changed to

OS.execute("/usr/local/bin/python3.9", [global_dir_path + "/get_credentials.py"], true)
by (594 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.