FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
09-26-2024 12:06 AM
Hello,
I´m trying to test an app with Python and Flask and Gunicorn as wsgi. If I configure Gunicorn to bind the address with port (0.0.0.0:5001), I can access the address http://<ipaddres>:5001. If I try Gunicorn binding to unix socket and bind the proxy of package manif...
The snap is like below.
Does anyone have any idea about what can be the problem?
Solved! Go to Solution.
09-26-2024 03:05 PM
Hi @rlilla
In our sample form the sdk (samples-python/webserver) the proxyMapping is done like this:
"services": {
"proxyMapping": [
{
"name": "sdk-py-webserver",
"url": "/python-webserver",
"binding": "unix://{$SNAP_DATA}/package-run/sdk-py-webserver/web.sock",
"restricted": []
}
]
And in the snapcraft.yaml the package-run slot is defined like this:
slots:
...
package-run:
interface: content
content: package-run
source:
write:
- $SNAP_DATA/package-run/${CRAFT_PROJECT_NAME}
I would suggest you to look into this example and see where the differences are.
Best regards,
Nick
10-02-2024 10:15 PM
I took the webserver example and just modified the main.py to use flask. But I still have the Not Found error when I true to open https://127.0.0.1:8443/python-webserver
The service is running fine.
10-03-2024 04:09 PM
@rlilla ,
Might the issue just be a typo? You have unix:/// in your proxy mapping instead of unix://
10-03-2024 04:23 PM
I don´t think so because I used the same proxy mapping of the webserver example and it worked fine. Maybe the problem is because we have https connection with the ctrlX and flask is working for http.
10-03-2024 04:27 PM
So you were able to access the flask server using the proxy mapping in the sample? If you changed nothing else, doesn't that point to the mapping being the issue?
10-03-2024 07:23 PM
Not the flask server. Only the http server used in the example. If I just change the main.py including Flask instead of htt.server, the it doesn´t work.
10-03-2024 07:32 PM - edited 10-03-2024 07:32 PM
The proxy mapping should handle HTTP & HTTPS. See documentation here.
Are you installing the app in the virtual CORE before executing? In that case, the sample code runs the unix socket server, not http.
def run_webserver_unixsock():
"""run_webserver_unixsock"""
sock_dir = os.getenv("SNAP_DATA") + "/package-run/sdk-py-webserver/"
if not os.path.exists(sock_dir):
os.makedirs(sock_dir)
sock_file = sock_dir + "web.sock"
try:
os.unlink(sock_file)
except OSError:
pass
with web.unix_socket_server.UnixSocketServer(
sock_file, web.request_handler.RequestHandler
) as http_server:
print("UNIX SOCKET server started - listening on", sock_file, flush=True)
http_server.serve_forever()
http_server.server_close()
os.remove(sock_file)
I would suggest trying some remote debugging to see where this is getting hung up.
10-05-2024 04:05 PM
After reading carefully the documentation about the reverse proxy, I realized that I was using the incorrect route in Flask. I had @app.route('/'). After changing to @app.route('/python-webserver'), it worked. Thanks a lot for your support.