mabass Posted October 11, 2020 Posted October 11, 2020 Hi, figured it's better to ask here before going straight to customer service. If I'm mistaken and both questions are better directed towards them let me know. i'm currently trying to migrate my flask sandbox (intended to provide python scripts to others as simple web apps) to HelioHost and a few questions have cropped up.Fyi, I'm decent enough in Python (though not a computer scientist by profession) but woefully inexperienced when it comes to server and web administration. 1. Is there a decent way to debug the online-version of flask without relying too heavily on the CRON-jobs?Setting the debug-flag in app.run() to True does not seem to work, I assume it's globally disabled? 2. What's the proper way to request python modules? My flask app is currently missing at least one specific module to run properly. Thanks! PS:The Flask-Tutorial on the wiki (https://wiki.helionet.org/tutorials/flask) has an erroneous ";" in the flask.wsgi code, line 4.
Krydos Posted October 11, 2020 Posted October 11, 2020 1. Is there a decent way to debug the online-version of flask without relying too heavily on the CRON-jobs?Not really. Most of the log files are full of information from all of the users on the server, so we can't provide direct access due to the possibility that the logs contain private information from another user. There is the error log button in cpanel that you may not have seen yet. Sometimes it contains useful information, but most of the time an admin can get a more detailed error message. Cron jobs can usually do a pretty good job of emailing you the errors, but you can only use them twice a day so that limits the usefulness. If you want us to try to get you a better error message just post the URL to the flask app. Setting the debug-flag in app.run() to True does not seem to work, I assume it's globally disabled?Probably. Most of the time in a production environment you want potentially malicious visitors to your site to not see the error messages, because they could use them against you to find vulnerabilities in your code. PHP ships with error messages disabled by default for this reason, and it wouldn't surprise me if flask was the same way. 2. What's the proper way to request python modules? My flask app is currently missing at least one specific module to run properly.Make a post in customer service, and include your username, server, and python version that you're using. You can just reply to this thread if you want rather than making a new post. Not a big deal. The Flask-Tutorial on the wiki (https://wiki.helionet.org/tutorials/flask) has an erroneous ";" in the flask.wsgi code, line 4.Wow, you're right. That semicolon has probably been there for 4 years or more. It works with it there and it works without it there so erroneous might be too strong of a word since it doesn't cause an error. I would agree with the word unneeded though. I edited the wiki. Thanks for pointing that out.
mabass Posted October 11, 2020 Author Posted October 11, 2020 (edited) Thanks. I did indeed miss the error log. The application fails at this import statement: from flask_wtf import FlaskFormFlask-wtf on the server is 0.14.2, which tries to import a deprecated werkzeug-function. This has been fixed in 0.14.3As per modules:As far as I can tell I only need pdfrw==0.4.idna==2.9 isn't on module-list but should be a default python module iirc.A few more modules on the server are out of date, though I have yet to see if they break anything.beautifulsoup4flaskflask-wtfjinja2soupsieveurllib3wtforms Wow, you're right. That semicolon has probably been there for 4 years or more. It works with it there and it works without it there so erroneous might be too strong of a word since it doesn't cause an error. I would agree with the word unneeded though. I edited the wiki. Thanks for pointing that out.Heh, I forgot how lenient Python actually is. I was wondering why no one had complained about their flask app not working despite following the tutorial. Edited October 11, 2020 by mabass
Krydos Posted October 11, 2020 Posted October 11, 2020 There you go https://krydos.heliohost.org/cgi-bin/modules37.py
mabass Posted October 12, 2020 Author Posted October 12, 2020 (edited) Awesome. Seems to work fine. I'm now running into pathing issue, probably due my inexperience with .wsgi and server/web admin in general: One app dynamically creates img src links, the images are within the /static/ folder hierarchy.The paths are created here https://github.com/Wolfenswan/flask-sandbox/blob/master/projects/adx_abctrainer/adx_abctrainer.py#L10 As the tags are injected into existing html I can't use Jinja templates.Locally and on pythonanywhere I can provide the relative path to the static folder with '/static/adx_abctrainer/img/'.However on HelioHost this 404s, as it assumes 'https://mabass.heliohost.org' as root rather than 'https://mabass.heliohost.org/flask'/.Using '../static/adx_abctrainer/img/' is a functional workaround, but I feel I'm probably missing a best practice. Edited October 12, 2020 by mabass
Krydos Posted October 12, 2020 Posted October 12, 2020 If you start a url with a / it means start at the webroot, which is /home/mabass/public_html/ for that domain. If you run your app on a subdomain instead of a subdirectory you might get the results you're expecting. For instance if you created a subdomain called flask.mabass.heliohost.org then the webroot would be /home/mabass/public_html/flask/ and if you used a url that started with a / it would start at the webroot which seems to be what you're expecting. Also /static/adx_abctrainer/img/ is an absolute url path since it starts with a /. A relative path would start with a . (period) .. (two periods) or a directory name.
mabass Posted October 14, 2020 Author Posted October 14, 2020 (edited) Thanks, that helped a lot. After resolving a few more pathing issues everything seems to work as intended now Regarding git/version-control:Is it correct that I can only pull from an existing repository but neither commit/drop local changes? I couldn't find a command line access or the relevant backend-controls in cpanel Edited October 14, 2020 by mabass
Krydos Posted October 14, 2020 Posted October 14, 2020 From cpanel: Warning: Your system administrator must enable shell access to allow you to view clone URLS. We can't provide shell access on our shared hosting because it is too much of a security risk. If you need shell access to run git commands you would have to get a vps https://www.heliohost.org/vps/
mabass Posted October 15, 2020 Author Posted October 15, 2020 I figured, thanks. Another question if you don't mind:I tried adding an addon domain that directly points towards public_html/mabass.tk/ (identical with /flask/ for now), however, this now produces a 500 error due to (I assume) an issue in either the .htaccess or .wsgi.Any pointers what I need to look at? https://mabass.heliohost.org/mabass.tk/ works fine.
Krydos Posted October 15, 2020 Posted October 15, 2020 If you change the webroot you likely need to change your .htaccess too. I would start there. Make sure the paths make sense from the point of view of the new webroot.
mabass Posted October 20, 2020 Author Posted October 20, 2020 Not sure why, but I struggle at grasping mod_rewrite. I understand the general syntax and regex well enough, but the overall logic or structure eludes me. More precisely:I mirrored my flask-instance to into a dev- and live-/production-instance. Both work fine when accessing them from mabass.heliohost.org. However, the sub-domains I created for testing purposes all produce a 500:flask-dev.mabass.heliohost.org - to /flask-dev/tk.mabass.heliohost.org (for the mabass.tk addon domain) - to /flask-live/ As I understand it, I have to add a RewriteCond to .htaccess, so I added RewriteCond %{HTTP_HOST} ^flask-dev\.mabass\.heliohost\.org$ [NC] producing: RewriteEngine On RewriteBase / RewriteRule ^(media/.*)$ - [L] RewriteRule ^(admin_media/.*)$ - [L] RewriteRule ^(flask\.wsgi/.*)$ - [L] RewriteRule ^(.*)$ flask-dev/flask.wsgi/$1 [QSA,PT,L] RewriteCond %{HTTP_HOST} ^flask-dev\.mabass\.heliohost\.org$ [NC] RewriteRule ^(flask\.wsgi/.*)$ - [L] RewriteRule ^(.*)$ flask-dev/flask.wsgi/$1 [QSA,PT,L] Still, no luck.
Krydos Posted October 20, 2020 Posted October 20, 2020 There you go https://flask-dev.mabass.heliohost.org/ Here's what I put in your .htaccess to make it work: RewriteEngine On RewriteBase / RewriteRule ^(media/.*)$ - [L] RewriteRule ^(admin_media/.*)$ - [L] RewriteRule ^(flask\.wsgi/.*)$ - [L] RewriteRule ^(.*)$ flask.wsgi/$1 [QSA,PT,L]
mabass Posted October 21, 2020 Author Posted October 21, 2020 That works, thanks. Just so I get this right:My problem wasn't with the condition but that the subdomain was trying to route through a directory it couldn't find?And if, theoretically, I wanted it to work both with https://mabass.heliohost.org/flask-dev/ (which is now broken) and the subdomain I'd have to split the current RewriteRule into two more specific ones, one catering for each?
Krydos Posted October 21, 2020 Posted October 21, 2020 Correct. You were getting a 500 error because when you access flask-dev.mabass.heliohost.org your webroot is /home/mabass/public_html/flask-dev/ and since the .htaccess was redirecting with this line RewriteRule ^(.*)$ flask-dev/flask.wsgi/$1 [QSA,PT,L] it was looking for /home/mabass/public_html/flask-dev/flask-dev/flask.wsgi which didn't exist.
mabass Posted November 4, 2020 Author Posted November 4, 2020 Thanks! With some more tinkering I got it to work as intended.Just leaving my ht-access here, in case people google a similar issue and are looking for pointers: RewriteCond %{HTTP_HOST} ^mabass\.heliohost\.org$ [NC] RewriteRule ^(.*)$ flask-live/flask.wsgi/$1 [QSA,PT,L] RewriteCond %{HTTP_HOST} ^mabass\.tk$ [NC,OR] RewriteCond %{HTTP_HOST} ^mabass\.de$ [NC] RewriteRule ^(.*)$ flask.wsgi/$1 [QSA,PT,L]
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now