Forums

Can't access MySQL database?

Hello my app wont work and the error message I keep getting is this:

django.db.utils.ProgrammingError: (1045, "1045 (28000): Access denied for user '<lonto81>'@'ip-10-146-173-159.ec2.internal' (using password: YES)", '28000')

However I can connect to MySQL database through the bash console using the same user name and pass as in my settings.py file here:

DATABASES = { 'default': { 'ENGINE': 'mysql.connector.django', 'NAME': '<lonto81>$<lonto81$default>', 'USER': '<lonto81>', 'PASSWORD': '<Memelove87!>', 'HOST': 'mysql.server', } } So I can't figure out why my app can't access the same database?

get rid of the angle brackets -- it should be:

'NAME': 'lonto81$default',
'USER': 'lonto81', 
'PASSWORD': 'Memelove87!'

etc

you might also want to change your password, since you've just exposed it to the entire world ;-)

Thank you so much for your help and I will.

I removed all the angle brackets and changed my password, ran manage.py and reloaded the app. Still doesn't work, any idea's? Could you look at my account maybe and help me figure it out. Here's the error code I get now:

2015-02-22 23:22:51,398 :django.db.utils.ProgrammingError: (1045, "1045 (28000): Access denied for user 'lonto81'@'ip-10-146-173-159.ec2.internal' (using password: YES)", '28000')

Thanks again for your help.

I have that fixed and some how I managed to create another error and this one I have no idea how to fix:

'module' object has no attribute 'QuerySet', Here's my models.py and it say's the error is on line 4?

from django.db import models from django.core.urlresolvers import reverse

class EntryQuerySet(models.QuerySet): def published(self): return self.filter(publish=True)

class Entry(models.Model): title = models.CharField(max_length=200) body = models.TextField() slug = models.SlugField(max_length=200, unique=True) publish = models.BooleanField(default=False) created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True)

objects = EntryQuerySet.as_manager()

def __str__(self):
    return self.title

class Meta: verbose_name = "Blog Entry" verbose_name_plural = "Blog Entries" ordering = ["-created"]

Could someone look at my account and make sure I have it set up right? I'm really confused at this point. Thanks for the help and for putting up with this noob always breaking stuff.

I fixed that issue but have another error,

2015-02-23 05:49:33,698 :django.core.exceptions.ImproperlyConfigured: Module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" attribute/class

Looks like I'll never get this blog going lol

Hmm, that's interesting. We've seen that error in the past when people tried to run Django 1.7, but it looks like you're still using the system default version for Python 3.4, which is 1.6.

Either way, could you try editing your WSGI file (there's a link on the "Web" tab) and replacing the lines that say this:

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

with ones that say this:

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

...and see if that helps?

Thanks I edited my wsgi file like you suggested and I get the exact same error? Could you look at my files and make sure their set up correctly. Could it be that there's an error in my settings.py file maybe? Thanks again for your help.

Hmm, you seem to have a default PythonAnywhere web app there right now -- perhaps you've been changing things since this forum post?

I deleted it and installed a virtual env and then reinstalled it. Having a little trouble figuring out exactly how to edit the wsgi file to activate my virtual env. Keep getting the error: exec file not defined?

You shouldn't need to do anything in the WSGI file to activate the virtualenv these days -- we added the field to the "Web" tab to handle all of that for you a couple of weeks back. I guess we still have some incorrect documentation somewhere, though -- where did you find the instructions to use execfile?

Oops I think I found it on the codeship; http://thecodeship.com/deployment/deploy-django-apache-virtualenv-and-mod_wsgi/, could someone look at my wsgi file and let me know what to do to get my webapp to work? Thanks again.

The problem at the moment seems to be that the WSGI file is configured correctly, but there's no web app source code for it to serve. You have this:

path ='/home/lonto81/webapps/myapp'
if path not in sys.path:
    sys.path.append(path)

...which is absolutely fine, but there's no directory called webapps in your home directory.

OK I change it to:

path = '/home/lonto81/qblog/blog' if path not in sys.path sys.path.append(path)

Now I'm getting this error: django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Deleted and reinstalled via a new virtual enviroment but now when I try to check if it works the page loads forever and nothing ever happens??

I wonder if it could be some sort of import error. Would you run through the steps in here and let us know if it reveals anything?

https://www.pythonanywhere.com/wiki/DebuggingImportError

I don't know what I'm doing wrong. I works fine on my local machine but for the life of me I can't get it deployed and working on pythonanywhere.com. I've tried running it in virtualenvs and outside of them and have reconfigured it every way I can find and still no luck. Could it be a problem when I'm umcompressing the zip file or perhaps where I'm unzipping it? The place I have been unzipping it is /home/lonto81.

Ok so I was using the wrong version of django and python! I now noobie mistake lol. So I reinstalled my app in a new virtualenv running the same version of django and python as the app was created with, Django 1.7.4 and python 3.4. Anyway now it loads but it's loading the "Hello World" html code from the WSGI file? I think I didn't edit the WSGI file right or maybe my sys path is wrong? Here's the WSGI file after I edited it,

+++++++++++ DJANGO +++++++++++

To use your own django app use code like this:

import os import sys

assuming your django settings file is at '/home/lonto81/mysite/settings.py'

path = '/home/lonto81/.virtualenvs/myvirtualenv/qblog' if path not in sys.path: sys.path.append(path)

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

then, for django >=1.5:

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

or, for older django <=1.4

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

Thanks again for your help, so close but not there yet but I wont give up until I get this site up and running. Thanks again for your patience and all of your help.

Whew I actually just got it up and running. I wasn't editing the WSGI file right. Had my sys path in wrong. Thanks again for all of your help.

I actually am having an issue with my static files not being used? I've read a couple of people's forums having similar issues but I'm really confused as to how to fix this issue. Could someone look at my code and help me? Thanks again for your help.

I've also tried doing what was outlined here, https://www.pythonanywhere.com/wiki/VirtualEnvForNewerDjango; but to no avail either.

hey lonto81,

For your static files problem, I see that your website is requesting static resources such as http://lonto81.pythonanywhere.com/static/css/bootstrap.min.css

However, you do not have a static directory setup for your webapp.

Take a look at our wiki here and other forum posts for reference.

Keep experimenting- seems like you are getting there! Also, imagine if instead of just setting up a static directory from your web interface, you also needed to write and tweak server code to serve up the static files yourself while you are struggling with this. This is why PythonAnywhere is AWESOMEE!!!

Conrad

Thanks Conrad. Ok I got it fixed to where my css files are being found for my main page but not for the admin page?

It looks like your static file mapping for /static/admin isn't quite right -- it's missing the virtualenv name in the path you're specified.

Right now I have the path as /home/lonto81/.virtualenvs/myvirtualenv/qblog/blog/admin/static, I know that's not right as it's not working either but I can't figure out what the right path should be.

I can see it's trying to access /static/admin/css/base.css, so I've change the path to /home/lonto81/.virtualenvs/myvirtualenv/qblog/static/admin/css, and /static/admin/css, no change?

Do you see how you don't actually have a folder called admin at "/home/lonto81/.virtualenvs/myvirtualenv/qblog/static/admin/"?

Two solutions to that:

  1. try running ./manage.py collectstatic (and try to understand what that does)
  2. make your /static/admin/ url point to something like /usr/local/lib/python3.4/dist-packages/django/contrib/admin/static/admin/ (also try to understand why this is the case)

Also, as an aside, I would suggest understanding more about how virtualenvs work- you don't actually need to have your source code/your program/webapp running inside the virtualenv folder structure. Instead, you can have code/processes anywhere you want, but you need to activate your virtualenv before you run it.

Thanks Conrad! I'm running on no sleep here. Yeah I probably should have caught that I was pointing that at directory that wasn't there. Thanks man, it works now!

I'm installing a mezzanine blog and I keep getting the error, "The SECRET_KEY must not be empty" but it's under my local settings.py file and it's not empty? Any clues on how to fix this? Thanks again for your help.

Perhaps it's picking up the wrong settings file from somewhere? Do you have any other files called settings.py, or any directories called settings?

Yes I have local_settings.py and then settings.py?

Thanks Giles I got it fixed but yet I have another problem. My blog is working but I can't get my img files or the admin for mezzanine to work correctly. Heres my settings.py file for my static and media urls and roots:

URL prefix for static files.

Example: "http://media.lawrence.com/static/"

STATIC_URL = "/static/"

Absolute path to the directory static files should be collected to.

Don't put anything in this directory yourself; store your static files

in apps' "static/" subdirectories and in STATICFILES_DIRS.

Example: "/home/media/media.lawrence.com/static/"

STATIC_ROOT = "/home/lonto81/.virtualenvs/techblog/moderna/static/"

URL that handles the media served from MEDIA_ROOT. Make sure to use a

trailing slash.

Examples: "http://media.lawrence.com/media/", "http://example.com/media/"

MEDIA_URL = STATIC_URL + "img/"

Absolute filesystem path to the directory that will hold user-uploaded files.

Example: "/home/media/media.lawrence.com/media/"

MEDIA_ROOT = "/home/lonto81/.virtualenvs/techblog/moderna/static/img/"

Also I have this under my web tab for them both: /static/ /home/lonto81/.virtualenvs/techblog/moderna/static /media/ /home/lonto81/.virtualenvs/techblog/moderna/static/img /static/admin/ /home/lonto81/.virtualenvs/techblog/Lib/site-packages/django/contrib/admin/static/admin

Never mind I figured out what I was doing wrong and now the admin interface and my images are showing on my site. I had to edit the path to my static/admin and then run the python manage.py collectstatic command and it worked! I have another, issue with my site. When I edit or post things and click the "view on site" button from within my admin panel, it opens up a new tab but it goes to my local machines IP address, 127.0.0.1:8000, I have no clue how to fix this. Thanks again for you help.

Never mind I got it figured out.

I need help with what is probably a very simple problem. Within my admin panel I can create blog entries but only on the blog page, I would like to be able to choose where I post my blogs? But I can't figure out yet how to change that. Also there is a drop down menu on the pages page and I would like to add "blog" to what you can create. I've moved the blog folder containing the blog html into the pages folder and reloaded my app and nothing happened, so I moved it back to templates. Could someone help me?

Heh, well, that sounds a bit more like helping you to build a website rather than helping you to host a website, so I'm afraid it's probably outside of our remit as staff... Maybe one of our other friendly users will be able to help. Otherwise, you could try codementor

Thanks Harry!

I'm having trouble updating my robots.txt file, I've changed it to this:

User-agent: * Disallow:

from this:

User-agent: * Disallow: /

I reload my website and go to http://lonto81.pythonanywhere/robots.txt and it still shows the robots.txt file as

User-agent:* Disallow: /

Any suggestions as to how to fix this?

I got my robots.txt file fixed, I still can't connect to my MySQL database however. I've changed the password, updated all my settings and then reloaded the web app and every time it throws an error; so I go change everything back and use sqlite3 instead. What am I doing wrong? Thanks in advance.

Never mind I got it up and running now. I had to install python-mysql since my app is using python 2.7

My robots.txt file looks like this:

User-agent: * Allow: /

Sitemap: http://http://lonto81.pythonanywhere.com/sitemap.xml

But I can't figure out how to get rid of the extra http:// at the beginning of my sitemap. Could someone help me.

I just see

User-agent: *
Disallow: /

in your robots.txt file

Sorry I was messing with it. It's back to where it say's:

User-Agent:* Allow:/

Sitemap: http://http://lonto81.pythonanywhere.com/sitemap.xml

I don't really know what was causing that issue but I went and created a new sitemap file, deleted the old one, uploaded the new one, reloaded the web app and presto it works fine now.

Great news! :-)