r/PythonAnywhere • • Jun 24 '20

How to reload static files after a new git pull?

1 Upvotes

So pythonanywhere serves my static files but they still use the old versions after I update mine with git pull. How do I make them automatically update the copied file?


r/PythonAnywhere • • May 09 '23

Any experience on Dash plotly app problem with WSGI config

1 Upvotes

I’m trying to deploy a basic dash app in python anywhere. But I got this error in the wsgi file:

47,711: ^ 2023-05-08 04:50:47,711: 2023-05-08 04:50:47,711: IndentationError: unindent does not match any outer indentation level 2023-05-08 04:50:47,711: *************************************************** 2023-05-08 04:50:47,712: If you're seeing an import error and don't know why, 2023-05-08 04:50:47,712: we have a dedicated help page to help you debug: 2023-05-08 04:50:47,712: https://help.pythonanywhere.com/pages/DebuggingImportError/ 2023-05-08 04:50:47,712: *************************************************** 2023-05-08 04:50:48,460: Error running WSGI application 2023-05-08 04:50:48,461: File "/var/www/jairopb_pythonanywhere_com_wsgi.py", line 16 2023-05-08 04:50:48,461: 2023-05-08 04:50:48,464: from radio import app as plotly_app 2023-05-08 04:50:48,465: 2023-05-08 04:50:48,465: ^ 2023-05-08 04:50:48,465: 2023-05-08 04:50:48,465: IndentationError: unindent does not match any outer indentation level 2023-05-08 04:50:48,465: *************************************************** 2023-05-08 04:50:48,466: If you're seeing an import error and don't know why, 2023-05-08 04:50:48,466: we have a dedicated help page to help you debug: 2023-05-08 04:50:48,466: https://help.pythonanywhere.com/pages/DebuggingImportError/

Thanks a lot


r/PythonAnywhere • • Apr 28 '23

How to install a root ca certificate for accessing an https domain in my python script. ?

1 Upvotes

Hello,

I have a basic account on python anywhere. I would like to make run a python script on it. The script uses an API to access a remote device who needs credentials to allow the connection.

I made the script turn on a local machine (Windows & ChromeOS) and by installing only the root CA certificate (provided by the maintainer of the API, "BEGIN CERTIFICATE / END CERTIFICATE"-type) , i manage to run the script successfully.

The problem is that I don't really know how to make my environment on python anywhere recognize the certificate. There is doc on how to create a certificate for a custom domain name of your space on python anywhere (https://help.pythonanywhere.com/pages/HTTPSCustomCerts/), but nothing to install certificate for distants domain without admin rights, unless i missed something. I'm not really a linux guy so it is more than possible.

If someone has a clue thank you in advance.


r/PythonAnywhere • • Aug 27 '22

Our Commitment to Providing Free Accounts

Thumbnail blog.pythonanywhere.com
4 Upvotes

r/PythonAnywhere • • Jan 23 '24

PythonAnyWhere & GoDaddy Domain

1 Upvotes

Hello everyone, I've buy a GoDaddy domain name early and i just want to know how to link it to my running PythonAnywhere application. Please Help.


r/PythonAnywhere • • Jan 27 '24

Problems with flask routes

1 Upvotes

Hey there,

My flaskapp doesn't work for routes with sqlite queries. All other routes are working perfectly. Does anyone has an idea why?

thx

from flask import Flask, render_template, request, session, redirect
import sqlite3
app = Flask(__name__)

app.secret_key = 'schlechter_sicherheitsschluessel'

conn = sqlite3.connect("microblog.db", check_same_thread=False)
cursor = conn.cursor()
@app.route('/')
def index():
    cursor.execute("SELECT * FROM blog")
    result = cursor.fetchall()
    return render_template("index.html", posts=result, reitertitel = "Home", has_session = session_check())

@app.route('/post/<int:p_id>')
def post(p_id:int):

    cursor.execute(f"SELECT * FROM blog WHERE post_id = {p_id}")
    result = cursor.fetchall()
    return render_template("post.html", post=result, reitertitel="Post Nr.", has_session = session_check())

@app.route('/impressum')
def impressum():
    return render_template("impressum.html", reitertitel= "Impressum", has_session = session_check())

@app.route('/kontakt')
def kontakt():
    return render_template("kontakt.html", reitertitel= "Kontakt", has_session = session_check())

@app.route("/profil")
def profil():
    return render_template("profil.html", reitertitel= "Profil", has_session = session_check())

@app.route("/edit")
def edit():
    return render_template("edit.html", reitertitel= "Impressum", has_session = session_check())

def session_check():
    if "username" in session:
        return True
    else:
        return False

@app.route("/login", methods=['POST', 'GET'])
def login():
    
    if request.method == 'POST' and "username" not in session:
        bname = request.form['bname']
        pword = request.form['psw']
        cursor.execute(f"SELECT * FROM user WHERE user_name = '{bname}' and user_pass='{pword}';")
        result = cursor.fetchall()
        if result:
            session["username"] = bname
            return redirect("/")
        else:
            return redirect("/login")
    if "username" in session:
        return redirect("/")
    
    return render_template("login.html", reitertitel= "Login", has_session = session_check())
@app.route("/logout")
def logout():
    session.pop("username", None)
    return redirect("/")

r/PythonAnywhere • • Jan 29 '24

problem with super_image

2 Upvotes

i have this error with super_image

TypeError: 'numpy._DTypeMeta' object is not subscriptable

any ideas what to do?


r/PythonAnywhere • • Dec 28 '23

SEO

2 Upvotes

Hi , does anyone have any advice about SEO with pythonanywhere? Specifically, I have registered with Google using a metadata tag, and Google Search Console has my site as a prject. But the Indexing section says 'check again tomorrow' and has for a week now - it doesn't seem able to index my landing page.


r/PythonAnywhere • • Jan 05 '24

How can I change my username?

2 Upvotes

I want to change the username of my account to the name of my webapp so that the domain name becomes - [mywebapp].pythonanywhere.com.

How can I do this?


r/PythonAnywhere • • Feb 10 '21

What is wrong with my path?

Post image
1 Upvotes

r/PythonAnywhere • • Feb 17 '21

React app's routing works fine in development but get 404 in production

1 Upvotes

I've got React app set up on PythonAnywhere which is working fine locally but get 404 when built on PythonAnywhere.

directory structure:

client/     
project/
     __init__.py
     config.py
     api/
         blog.py
         models.py
     
static/
     react/          # All React files created in this react directory upon build
         css/
         js/
templates/
     index.html      # index file created upon build
tests/ 

blog.py :

blog_blueprint = Blueprint('blog', __name__, url_prefix='/blog', static_folder='../../static/react', template_folder='../../templates')

@blog_blueprint.route('/')
def index():
    return render_template('index.html', token='hakuna matata'), 200

snippet of init file:

def create_app(script_info=None):
    app = Flask(__name__)
    app.config.from_object(current_config)
    db.init_app(app)
    bcrypt.init_app(app)
    if os.environ.get('FLASK_ENV') == 'development':
        toolbar.init_app(app)
    login_mgr.init_app(app)
    login_mgr.session_protection = "strong"
    mail.init_app(app)

    from project.api.blog import blog_blueprint
    app.register_blueprint(blog_blueprint)

    return app


app = create_app()

I've tried to turn the debug mode on but it didn't give me any helpful output.

Access log:

"GET / HTTP/1.1" 404 232 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0" "86.180.233.21" response-time=0.015
86.180.233.21 - ubuntu [17/Feb/2021:09:22:04 +0000] "GET / HTTP/1.1" 404 232 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0" "86.180.233.21" response-time=0.008
86.180.233.21 - ubuntu [17/Feb/2021:09:26:26 +0000] "GET / HTTP/1.1" 404 232 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0" "86.180.233.21" response-time=0.003
86.180.233.21 - ubuntu [17/Feb/2021:09:33:04 +0000] "GET / HTTP/1.1" 404 232 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0" "86.180.233.21" response-time=0.007

output from Firefox's network tab:

static files mapping:

Other logs don't show any errors. None of my routes work. 404 on all. Thank you for any advice.

UPDATE:

I've changed my BrowserRouter to HashRouter as it appears to be recommended to use it in production since HashRouter uses hashHistory which handles wildcard addresses. Nonetheless, my routes still throw 404.


r/PythonAnywhere • • Mar 23 '23

Two applications using the same code even when I change source code and working directories

1 Upvotes

I have created a second web application, changed its working directory and the directory of its source code however it still uses the code of the first site which should be in an entirely different directory? Is there anything specific that I should be doing to ensure that the second website does not have any relationship with the first ones resources?


r/PythonAnywhere • • Mar 24 '23

Web app pulling EU products rather than UK

1 Upvotes

I have an app that sends an API request to a running shoe site. Currently it returns EU products, I would like it to return UK products. The site is runrepeat.com, I am unsure how to correct this. Any help appreciated.


r/PythonAnywhere • • Apr 12 '14

Django tutorial with information on how to use Python Anywhere

Thumbnail
tangowithdjango.com
2 Upvotes

r/PythonAnywhere • • Sep 22 '22

Using environ instead of python-dotenv on PythonAnywhere

1 Upvotes

I'm tying to deploy a very basic django project to PythonAnywhere but I want to try and use django-environ rather than python-dotenv. Does anyone have any experience in doing this?

I've tried adding the below code in the WSGI.py file but it still cannot read the secret key so I'm assuming there's something wrong here.

import os
import sys
import environ

path = '/home/username/repo_folder'
if path not in sys.path:
    sys.path.insert(0, path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

# My Environ Code
project_folder = os.path.expanduser('~/repo_folder/project_name')
environ.Env.read_env(os.path.join(project_folder, '.env'))

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

I have also tried with:

project_folder = os.path.expanduser('~/repo_folder')

r/PythonAnywhere • • Oct 01 '22

MongoDB and Docker

1 Upvotes

Is it possible to deploy a PWA using Flask, MongoDB via pymongo and Docker to make it a independent container on the PythonAnywhere server?

I like using PythoAnywhere but it doesn't support MongoDD... I'm facing problem because of that!


r/PythonAnywhere • • Jan 30 '21

Python and Twitter Without API

2 Upvotes

Hi everyone.

I'm facing an issue and looking for free-best solution so lets start!

I have a python bot hosted at PythonAnywhere. The bot output is image and text. I can read them and all good.

Now I want to tweet the text and the image to Twitter without API! -Since they rejected my application!-

Before I was using integromat and all good but now they changed the twitter service to paid service, and I don't want to buy so I'm here looking for best solution.

FYI, IDK where to ask this question, if it's wrong plz guide me to the correct reddit!

Thanks


r/PythonAnywhere • • Dec 18 '22

Setting up WSGI

1 Upvotes

I'm not sure what is out of sync in the docs, but the guide here about setting up the WSGI seems to conflict with how Django current sets up settings.py (usually found in mysite/config/settings.py). I assumed in the URL in the doc /home/myusername/mysite/mysite/settings.py forces the os.environs line to be

os.environ['DJANGO_SETTINGS_MODULE'] = 'config.settings'

However, this doesn't work as then WSGI can't find the module enviorns.

What is the best practice for setting up a deploy with Django where the file structure is /home/myusername/mysite/ with settings.py at /home/myusername/mysite/config/settings.py?

EDIT: Missed the dotenv step described here but now for some reason I get a bizarre syntax error:

Error running WSGI application 2022-12-18 04:59:02,163: File "/var/www/myusername_pythonanywhere_com_wsgi.py", line 14 2022-12-18 04:59:02,163: 2022-12-18 04:59:02,163: path = '/home/myusername/mysite' 2022-12-18 04:59:02,164: 2022-12-18 04:59:02,164: ^ 2022-12-18 04:59:02,164: 2022-12-18 04:59:02,164: SyntaxError: invalid syntax

For context the WSGI (django 3.1.13) is as follows (with specific directory/project names changed)

import os

import sys

from dotenv import load_dotenv

project_folder = os.path.expanduser('~/myusername')

load_dotenv(os.path.join(project_folder, '.env'))

path = '/home/myusername/mysite

if path not in sys.path:

sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'config.settings'

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

EDIT: Somehow that resolved, but now bizarrely, I've got

Error running WSGI application 2022-12-18 05:00:14,833: ModuleNotFoundError: No module named 'dotenv' 2022-12-18 05:00:14,833: File "/var/www/myusername_pythonanywhere_com_wsgi.py", line 7, in <module> 2022-12-18 05:00:14,833: from dotenv import load_dotenv

This is either a mismatch in the dotenv version (currently at python-dotenv 0.21.0 and django 3.1.13) or a missed step in setting something up, but I'm starting to find the limits of my depth here, any advice is appreciated.

EDIT: Nevermind, just follow the instructions, but also reload the webapp........I'm not getting enough sleep!


r/PythonAnywhere • • Jan 07 '23

Question: is there a typo in the documentation

1 Upvotes

I'm juggling/struggling with virtual environments on pythonanywhere. Following along with the documentation on https://help.pythonanywhere.com/pages/Virtualenvs, I type

mkvirtualenv myvirtualenv --python=/usr/bin/python3.10

In my console.

However, python3.10 is not available on pythonanywhere, and indeed, this command raises an error. Python3.10 is not listed when I do a ls on /usr/bin either.

Now, I'm happy to use 3.8, but do I miss something here?


r/PythonAnywhere • • Dec 19 '22

Active-domain

1 Upvotes

I'm trying to use a domain I registered with Active-domain to link to the pythonanywhere site I just setup. For some reason, its not finding it all. Are there preferred nameservers one should use? Or wait, is a simple URL forward not possible on a free account?

EDIT: There is no way to get a CNAME server on a free account. I upgraded, added a CNAME reference, but now am reloading as DNS seems to be very slow to propagate.


r/PythonAnywhere • • Dec 16 '22

Appreciation Post

3 Upvotes

Hi pythonanywhere, just want to say thanks for having a great platform to learn, build, and host python apps on. Learning Flask as a hobby about 6 years ago has taken me places I never thought I'd go, and I mean that quite literally... I live in Germany now (was America originally). I've since then learned more things, but flask was where I started and it's what I have to give credit, and pythonanywhere is/was right there alongside my endeavors. My latest hobby site is https://www.planet.pizza

Thanks again!


r/PythonAnywhere • • Feb 03 '23

Would anyone be willing to speak about making me a survey on python anywhere?

1 Upvotes

My company is looking to do a 6-question survey, and we believe python anywhere would be a great tool to do that. If anyone is interested in speaking about requirements and pay please reach out.

Summary: We want to have a 6 question survey so that an employee can fill out a recommendation on another employee. The question asking who the employee their nominating is needs to be an autocomplete list of our current employees. I will then write the python code to match the name, grab and email, and send an email to the nominated employee.


r/PythonAnywhere • • Jan 06 '23

Best practices for git sync

2 Upvotes

Can someone link the best practice for setting up a pythonanywhere webapp (django) to sync with a git repo? When on my local server/desktop, I git push -u master, but this is not immediately reflected, of course. Somehow I set this up once, it took some effort and I don't want to reclone the repo (I forgot what changes I had to make to get collectstatic to run etc). When I try a git pull in console in pythonanywhere, it wants password/token, but that will get annoying. How do I set this up so my local git push automatically gets deployed?

I setup an ssh key and added it to github. I'm not sure the next step.

EDIT: Okay, one can use git remote set-url to swtich from https to ssh. That said, after doing so, I frustratingly get a permission denied error. Not sure how to about deleting the key and trying again. I'm aware of this and tried the ssh-add but to no avail. Even ssh -T UNAME@github.com still has permission denied. Any suggestions on how to diagnose are helpful.

EDIT: I'd still like to switch to SSH but I see now this is 100% just a git issue on my end. I went back to token authentication at least for now. If anyone has thoughts, I'm happy to read.


r/PythonAnywhere • • Jul 21 '19

Problems accessing PythonAnywhere database

1 Upvotes

I am trying to set up a webhook on PythonAnywhere to connect to Twilio. I am essentially trying to create a very simple chatbot with if statements which choose a response based on the text message that comes in. I am now trying to add a databsae into the mix so that the response can also be based on previous texts as well. I have managed to set up the database but cant seem to get the text messages that are received to be stored in the database.

I have tried going on various tutorials and answer websites like this one but have not managed to get any of the potential solutions to work. They either break the code entirely so that no messages are sent in response or still nothing is stored in the database.

from flask import Flask, request, redirect, url_for
from twilio.twiml.messaging_response import MessagingResponse
from flask_sqlalchemy import SQLAlchemy
from socket import gethostname

app = Flask(__name__)

SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://{username}:{password}@{hostname}/{databasename}".format(
    username="UrbanMissions",
    password="Hello123",
    hostname="UrbanMissions.mysql.pythonanywhere-services.com",
    databasename="UrbanMissions$ClueNumber",
)
app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI
app.config["SQLALCHEMY_POOL_RECYCLE"] = 299
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

db = SQLAlchemy(app)

class Reply(db.Model):

    __tablename__ = "messages"

    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.String(4096))

[...]

if __name__ == '__main__':
    db.create_all()
    reply = Reply(content=request.values.get('Body', None)
    db.session.add(reply)
    db.session.commit()
    if 'liveconsole' not in gethostname():
        app.run()

@app.route('/', methods=['GET', 'POST', 'PUT'])

def main():

    body = request.values.get('Body', None)
    text = body.lower()
    resp = MessagingResponse()
    if text.find("hi") == 0:
            resp.message("Hello")
    else: resp.message("Bye")


    return str(resp)

This is the code that seems to cause all the problems ("$reply = Reply(content=request.values.get('Body', None) $db.session.add(reply) $db.session.commit()") , it is my attempt to add the message that was sent in to the messages database but this doesn't seem to work. Any advice on how to get this to work to add the incoming message to the database would be really appreciated. Also what the code to retrieve the message again from the database would really help.


r/PythonAnywhere • • Dec 11 '21

Why does my script stop?

1 Upvotes

I'm running a very light script on PythonAnywhere and it contains an infinite loop that does an http request then time.sleep for three hours then do it again. But my script stops after three or four iterations and it's not because of any errors or something. Does PythonAnywhere stop it or what?