Python project encoding error

It’s an error that occurs while setting up a new server app
PM2 is set as below

module.exports = {
  name: "{domain}",
  script: "uvicorn main:app --port 9623",
  args: "",
  log_type: "json",
  cwd: "/home/esmaster/{domain}/current",
  interpreter : "/usr/bin/python3",
  // Note: We detected that this web app is running on a server with multiple CPUs and hence we are
  // setting *instances* to "max" and *exec_mode* to "cluster_mode" for better performance.

  // instances : "max", // change the value to "1" if your server has only 1 CPU
  // exec_mode : "cluster_mode", // remove this line if your server has only 1 CPU
  env: {
    "PORT": 9623,
    "CI": 1,
    "NUXT_TELEMETRY_DISABLED": 1
  }
}

An encoding error occurs.
Does the same setting work in my local area
When I go up to the server, the following error message occurs
SyntaxError: Non-UTF-8 code starting with '\\x82' in file /usr/bin/bash on line 2, but no encoding declared; see https://python.org/dev/peps/pep-0263/ for details\n
I’m asking if there’s any way

If you run it with the message below, it works normally
pm2 start "python3 -m uvicorn main:app" --name {domain}

Add the above code to the main file

if __name__ == "__main__":
    uvicorn.run("main:app", port=os.environ.get('PORT', 5000), reload=False)

I changed the pm2 deployment to resolve it.

module.exports = {
  name: "{domain}",
  script: "main.py",
  args: "",
  log_type: "json",
  cwd: "/home/esmaster/{domain}/current",
  "interpreter": "/usr/bin/python3",
  // Note: We detected that this web app is running on a server with multiple CPUs and hence we are
  // setting *instances* to "max" and *exec_mode* to "cluster_mode" for better performance.

  instances : "1", // change the value to "1" if your server has only 1 CPU
  // exec_mode : "cluster_mode", // remove this line if your server has only 1 CPU
  env: {
    "TZ": "Asia/Seoul",
    "PORT": 9623,
    // "CI": 1,
    // "NUXT_TELEMETRY_DISABLED": 1
  }
}
1 Like

Awesome, I’m glad you were able to figure it out!

It’s been a while since I’ve deployed a Python app. We do have a few guides:

1 Like