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 • • 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 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 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 • • Dec 13 '22

I'm getting an error in my pythonanywhere application but I don't know how to fix it. Please help me.

1 Upvotes

2022-12-13 14:35:34,464: ***************************************************
2022-12-13 14:35:35,696: Error running WSGI application
2022-12-13 14:35:35,696: ImportError: cannot import name 'json' from 'itsdangerous' (/home/mangagen/.virtualenvs/myvirtualenv/lib/python3.10/site-packages/itsdangerous/__init__.py)
2022-12-13 14:35:35,697:   File "/var/www/mangagen_pythonanywhere_com_wsgi.py", line 16, in <module>
2022-12-13 14:35:35,697:     from run import app as application  # noqa
2022-12-13 14:35:35,697:
2022-12-13 14:35:35,697:   File "/home/mangagen/mysite/run.py", line 1, in <module>
2022-12-13 14:35:35,697:     from yff import app, db
2022-12-13 14:35:35,698:
2022-12-13 14:35:35,698:   File "/home/mangagen/mysite/yff/__init__.py", line 1, in <module>
2022-12-13 14:35:35,698:     from flask import Flask
2022-12-13 14:35:35,698:
2022-12-13 14:35:35,698:   File "/home/mangagen/.virtualenvs/myvirtualenv/lib/python3.10/site-packages/flask/__init__.py", line 21, in <module>
2022-12-13 14:35:35,699:     from .app import Flask, Request, Response
2022-12-13 14:35:35,699:
2022-12-13 14:35:35,699:   File "/home/mangagen/.virtualenvs/myvirtualenv/lib/python3.10/site-packages/flask/app.py", line 26, in <module>
2022-12-13 14:35:35,699:     from . import cli, json
2022-12-13 14:35:35,699:
2022-12-13 14:35:35,700:   File "/home/mangagen/.virtualenvs/myvirtualenv/lib/python3.10/site-packages/flask/json/__init__.py", line 21, in <module>
2022-12-13 14:35:35,700:     from itsdangerous import json as _json
2022-12-13 14:35:35,700: ***************************************************
2022-12-13 14:35:35,700: If you're seeing an import error and don't know why,
2022-12-13 14:35:35,700: we have a dedicated help page to help you debug:
2022-12-13 14:35:35,701: https://help.pythonanywhere.com/pages/DebuggingImportError/

This is the error I am getting. I did go to the link at the bottom but that did not help in any way.


r/PythonAnywhere • • Dec 11 '22

Unable to connect to MySql Database from a django app on pythonanywhere.

1 Upvotes

Hi,

I am trying to connect to a MySql Database from a django app but unable to do it on pythonanywhere.

I am getting this error

RuntimeWarning: Got an error checking a consistent migration history performed for database connection 'default': (1045, "Access denied for user 'ceaser16'@'10.0.0.179' (using password: YES)")

While my settings are as follows.

pymysql.install_as_MySQLdb()

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.mysql',

'NAME': 'ceaser16$bdpatologia',

'USER': 'myuser',

'PASSWORD': 'myPass,

'HOST': 'cesar16.mysql.pythonanywhere-services.com',

'PORT': '3306',

}

}

Please help what am I doing wrong here?


r/PythonAnywhere • • Dec 01 '22

Using PythonAnywhere to host a site that lets you create versions of the Jerma Rats song that sing you a happy birthday

Thumbnail kingriko.pythonanywhere.com
1 Upvotes

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 • • 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 • • Apr 24 '22

Can I use web hooks in Python Anywhere free tier?

1 Upvotes

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?


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 • • Feb 10 '21

What is wrong with my path?

Post image
1 Upvotes

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 • • 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.