Hello, @Paarthvi Sharma thanks for the question.
The error message you are seeing indicates that the script file fetchdocs.sh
cannot be found. This could be because the file is not being deployed to the correct location in Azure.
When you deploy your application to Azure, you need to make sure that all the required files are included in the deployment package. This includes any scripts that your application needs to run.
One way to include the script file in your deployment package is to add it to your project directory and include it in your deployment package. You can do this by adding the following lines to your requirements.txt
file:
scripts/required_script.sh
This will include the required_script.sh
file in your deployment package.
Once the script file is included in your deployment package, you can modify your Flask application to use the correct path to the script file. You can use the os
module to get the absolute path to the script file. Here is an example:
import os
@app.route('/train', methods = ['POST'])
def train():
try:
script_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'scripts', 'required_script.sh'))
subprocess.run([script_path])
return jsonify({"Success" : "Script executed"}), 200
except Exception as e:
logging.exception("Exception in /train")
return jsonify({"error": str(e) }), 500
This code uses the os.path.abspath
function to get the absolute path to the script file. The os.path.join
function is used to join the path to the script file with the path to the parent directory of the Flask application. This ensures that the correct path to the script file is used, regardless of where the application is deployed.
hope this helps. Let me know if you have any further questions
-Grace