Forums

WSGI error on deploying

Hello,

i'm really new to python and django, expecially deploying websites with this method.

I've create a web aplication that totally works on my pc. here you can find the files: https://github.com/marcomalaguti/marcomalaguti

now, I followed this tutorial ( https://tutorial.djangogirls.org/en/deploy/ ) to deploy the website, but obviously something went wrong.

as per error log file, the problem is:

ImportError: No module named 'mysite'

this is the wsgi file on the pythoneverywhere server:

import os
import sys

path = '/home/marcomalaguti/marcomalaguti'  # usa il tuo username qui

if path not in sys.path:
    sys.path.append(path)

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

from django.core.wsgi import get_wsgi_application

from whitenoise.django import DjangoWhiteNoise

application = DjangoWhiteNoise(get_wsgi_application())

google says that 'mysite.settings' is correct.

Could you please help me to understand what's wrong?

thank you in advance!

[edited by admin: formatting]

This help page should help you work out what's going wrong.

If you're still perplexed after working through the stuff there, just let us know!

thank you giles, I solved the problem.

I have now other 2 question, but they're going out of the topic.

  1. I've read here that the only way to send mails via smtp is to use a gmail account. So I did it and on my pc (localhost) it works good! But when I've uploaded it on the server I always get this error:

    smtplib.SMTPAuthenticationError: (534, b'5.7.14
    <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbuS\n5.7.14
    -EpdJcgE443lnJmzjIZCVmIrjG0naRDy6hYEk7f0ywXcN-MUg2VuK8NPP4NnO5ST80R-8M\n5.7.14
    lhj8jbvZwifj7lCXDyyDdzfrGYGGlqG99dBet_vkAqL7sGsGBDmRoauDc1iRwyVi8ULLuI\n5.7.14
    _6-3Q7uuRbu1IuZATQEEchP2w7p1yjsxLrreCvMFp7EooK-AYdRTf405LJVuE1WmGFUSM5\n5.7.14
    lwkEaDoaloO9L3d6hJbusasGff75Y> Please log in via your web browser
    and\n5.7.14 then try again.\n5.7.14  Learn more at\n5.7.14 
    https://support.google.com/mail/answer/78754 y200sm4024718qkb.37 -
    gsmtp')
    

    It can't be an issue of ports or allow less secure apps because I've already done it and on my pc work good. What can it be?

  2. I'm not an expert in domains, but I've bought it: www.marcomalaguti.com In the control panel of the domain I made the redirect to the my pythonanywhere site: http://marcomalaguti.pythonanywhere.com/ Do you know why appears just a blank webpage?

[edit by admin: formatting]

  1. Check out the stuff at the bottom of the page you linked to, entitled Google security blocking and setting up an App-Specific password -- that has hints and tips of solving problems like that.
  2. It looks like you've set up your domain to do a "masked forward" to your PythonAnywhere site, which is where the code for your domain is served up by another server, which tries to embed your site inside that code. PythonAnywhere sites don't allow that, as it's a common trick used by hackers trying to abuse your site.

    What I'd recommend you do instead is rename your web app on the "Web" tab inside PythonAnywhere (use the pencil icon next to "marcomalaguti.pythonanywhere.com"). Change it to "www.marcomalaguti.com". Once you've done that, you'll see a new section appear, which will give you a value for a CNAME -- it will look something like webapp-12345.pythonanywhere.com. Go to your domain registrar's site, and set up a CNAME from "www" to that value, and your site will start working properly.

Hi Giles,

for the first point: the only thing that I was missing was the "app-specific password". I created it and on my pc works. I would like to test it on the pythonanywhere server but here the secondo ponit:

I changed the app name and I get the cname. So I went on the cpanel where I bought the domain and I've replaced the address. Now: if you go on my website, there is a redirect, but you can see that a pythonanywhere default message for new website appears, like if it does not see that I've uploaded my site. Same thing if go to the cname addreess.

What's the problem now ?

Hi there, when I lookup your www CNAME (for www.yourwebsite.com), I see that it points to yourwebsite.com. Instead, the CNAME should point to webapp-236176.pythonanywhere.com

You can check that you have it setup correctly on say http://mxtoolbox.com/

thank you conrad. the problem was the dns while I was looking at the redirect.

I've tested the email sending with the specific app password. And kepps giving sever error 500

What is giving a 500? Is it the google server? Or is this your website that's giving a 500? Or something else?

if you try to send an email from my website (http://www.marcomalaguti.com/contacts) and click submit, you'll receive back an error 500.

It's not the google server because on my localhost works good.

take a look at your error log to see why it is 500-ing?

this is the error:

smtplib.SMTPAuthenticationError: (534, b'5.7.9 Application-specific password required. Learn more at\n5.7.9  https://support.google.com/mail/?p=InvalidSecondFactor z29sm11158952qtz.16 - gsmtp')

But I'm using a app-specific password and it's correct. Otherwise it wuold not work on localhost. or not?

There are all sorts of reasons why your local machine may be treated differently by Google: Maybe you're logged in to Google from that IP and they can see that so it's OK, maybe they're using a different authentication method etc.

The error is pretty clear: You need an application-specific password and you need to use it correctly.

i'm sorry but I can't understand wha'ts wrong. I've used an app-specific password. What is the correct what to use it? I've just put it on the password variable in the settings file

Are you 100% sure you're using the same username and password on PythonAnywhere as you are locally? As you're using Django, do you have different settings on PythonAnywhere and locally, using (say) a local_settings.py file? It might be worth printing out the username and password in your code just before you try to send email (it will wind up in the server log, which is linked from the"Web" tab) to make sure.

If it's definitely the same on PythonAnywhere as it is locally then I must admit I'm as perplexed as you are, because the Google error looks pretty unambiguous, saying that the password you're using is not app-specific.

Perhaps we could look at your code? We can see it from our side but we always ask permission first.