Saturday, December 1, 2018

Re: Issue with Python 3.6 and Django 2.0 App Deployment on Shared Hosting

Hi Corey,
I'm having what seems to be the exact same problem with django/fcgi on bluehost shared hosting (getting a 404 in the browser but the appropriate html on the command line; I posted my question here), so I'm wondering if/how you ended up resolving it.  Any tips would be greatly appreciated, thanks!!!
Annchen

On Friday, January 5, 2018 at 6:26:08 PM UTC-5, coreyj...@gmail.com wrote:
Thanks a million for your fast response! I greatly appreciate it. I have made those changes you recommended. I swear I looked at that a million times and couldn't see a difference. Thanks for pointing that out.  I also added to my settings file under templates the word 'INFO' rather than 'DEBUG' and I am able to get my debug.log file to simply now say: 

    Not Found: /

These changes are definitely getting me closer. Thank you! I still see the standard 404 page, however, and not the Django 404 page. If I run app.fcgi in my shell I still get all of the Django-specific html but the following errors remain:

WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!

I have tried looking at my fcgi_base.py which is where this error is coming from to see what I should modify:

The following code there states:


 for name,default in [('REQUEST_METHOD', 'GET'),
                             ('SERVER_NAME', 'localhost'),
                             #('SERVER_NAME', '50.87.249.197'),
                             #('SERVER_PORT', '33606'),
                             ('SERVER_PORT', '80'),
                             ('SERVER_PROTOCOL', 'HTTP/1.0')]:
 if name not in environ:
                             environ['wsgi.errors'].write(bytearray('%s: missing FastCGI param %s '
                                                       'required by WSGI!\n' %
                                                        (self.__class__.__name__, name), 'utf'))
                             environ[name] = default


That IP I believe is what bluehost recommended me to use but they can't assign me a port because I am on a shared server. When I type in:

netstat --listen

I can see the open ports and 33606 should be open...

I have tried commenting on the code lines above and trying my specific IP and and my port that I believe is open, but the result is the same.

Do you by chance see anything else I can try. If you would like I would be more than happy to send you any information you request that you think may be helpful in resolving this. Again, Thank you for your time and help! I greatly appreciate it!

Best wishes!

Corey






















On Friday, January 5, 2018 at 4:59:24 PM UTC-6, Matthew Pava wrote:

Looking at the .htaccess file and the example provided here:  https://docs.djangoproject.com/en/1.8/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-with-apache

It looks like you have a typo.

AddHandler fastcgi-script .fcgi

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]

 

In the RewriteRule line, you have a % instead of a $.

 

Also, your DJANGO_SETTINGS_MODULE doesn't have your project name specified.

 

Granted, these examples are from Django 1.8.

 

From: django...@googlegroups.com [mailto:django...@googlegroups.com] On Behalf Of coreyj...@gmail.com
Sent: Friday, January 5, 2018 3:01 PM
To: Django users
Subject: Re: Issue with Python 3.6 and Django 2.0 App Deployment on Shared Hosting

 

Hi! I am having the same problem. Did you get this to work yet? Any tips would be greatly appreciated:

 

I am using a shared server, linux, Django 2.0, Python 3.6.4, flup6. Because fastcgi is deprecated post Django 1.8 and Bluehost doesn't use WSGI and only FastCGI (mod_fastcgi) I am using what NetAngels made available: https://github.com/NetAngels/django-fastcgi

My .htaccess file is the project folder with my .fcgi file as is commonly recommended. My .htaccess reads:

AddHandler fastcgi-script.fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)% app.fcgi/$1 [QSA, L]

My .fcgi file reads:

#!/homeX/user/python3.6/bin/python36
import sys, os
project_name = "app"
sys.path.insert(0, "homeX/user/python3.6/bin/python36")
sys.path.append("directory/of/my/project/app")
sys.path.append("directory/of/my/project/app/app")
sys.path.append("directory/of/my/project/app/app/app")
sys.path.append("directory/of/site-packages")
sys.path.append("directory/of/site-packages/flup")    
sys.path.append("directory/of/site-packages/django")  
os.chdir("directory/of/my/project/app/app/app")
 
os.environ['DJANGO_SETTINGS_MODULE'] = "settings"
from django_fastcgi.servers.fastcgi import runfastcgi
from django.core.servers.basehttp import get_internal_wsgi_application
wsgi_application = get_internal_wsgi_application()
 
runfastcgi(wsgi_application, method="prefork", daemonize="false", 
minspare=1, maxspare=1), maxchildren=1)

I have made sure to:

chmod 0755 app.fcgi

I am able to type into the linux SSH:

app.fcgi

This is what comes up in the SSH terminal:

WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Not Found: /
Status: 404 Not Found
Content-Type: text/html
X-Frame-Options: SAMEORIGIN
Content-Length: 2021
 
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Page not found at /</title>
<meta name="robots" content="NONE,NOARCHIVE">
<style type="text/css">
html * { padding:0; margin:0; }
body * { padding:10px 20px; }
body * * { padding:0; }
body { font:small sans-serif; background:#eee; color:#000; }
body>div { border-bottom:1px solid #ddd; }
h1 { font-weight:normal; margin-bottom:.4em; }
h1 span { font-size:60%; color:#666; font-weight:normal; }
table { border:none; border-collapse: collapse; width:100%; }
td, th { vertical-align:top; padding:2px 3px; }
th { width:12em; text-align:right; color:#666; padding-right:.5em; }
#info { background:#f6f6f6; }
#info ol { margin: 0.5em 4em; }
#info ol li { font-family: monospace; }
#summary { background: #ffc; }
#explanation { background:#eee; border-bottom: 0px none; }
</style>
</head>
<body>
<div id="summary">
<h1>Page not found <span>(404)</span></h1>
<table class="meta">
<tr>
<th>Request Method:</th>
<td>GET</td>
</tr>
<tr>
<th>Request URL:</th>
<td>http://localhost/</td>
</tr>
 
</table>
</div>
<div id="info">
 
<p>
Using the URLconf defined in <code>app.urls</code>,
Django tried these URL patterns, in this order:
</p>
<ol>
 
<li>
 
admin/
 
</li>
<li>
 
million/
 
 
</li>
</ol>
<p>
 
The empty path didn't match any of these.
</p>
 
</div>
 
<div id="explanation">
<p>
You're seeing this error because you have <code>DEBUG = True</code> in
your Django settings file. Change that to <code>False</code>, and Django
will display a standard 404 page.
</p>
</div>
</body>
</html>

However, when I go to my website.com/app it shows me the standard 404 error generated by my host. If I go to my website.com/app/app.fcgi it shows me the contents of the file and not the HTML generated when I run app.fcgi. In the main settings.py file,

DEBUG = True
ALLOWED_HOSTS = ['*']

But it will not show me the error generated by Django. I have tried putting in host information, socket information, etc. and it always give me a 500 error when I go to my website.com/app.

I have messed around trying to connect FastCGIExternalServer to my .fcgi file but I can never get the HTML as when I simply just use the default settings that I get from NetAngels referenced above, despite the WSGI warnings. It seems that because it is outputting my HTML, that everything is fine (i.e., it will still display my HTML) because if I try to correct for the WSGI warnings/errors, I don't ever see any of the HTML that Django is generating which is below the WSGI errors.

I was able to get a debug.log working and this is what it says:

Exception while resolving variable 'name' in template 'unknown'.
Traceback (most recent call last):
File "/home2/usr/python3.6/lib/python3.6/site-
packages/django/core/handlers/exception.py", line 35, in inner
response = get_response(request)
File "/home2/usr/python3.6/lib/python3.6/site-
packages/django/core/handlers/base.py", line 113, in _get_response
resolver_match = resolver.resolve(request.path_info)
File "/home2/usr/python3.6/lib/python3.6/site-
packages/django/urls/resolvers.py", line 523, in resolve
raise Resolver404({'tried': tried, 'path': new_path})
django.urls.exceptions.Resolver404: {'tried': [[<URLResolver <module 
'million.urls' from 
'/home2/usr/public_html/websitename/app/app/million/urls.py'> 
(None:None) '^million/'>], [<URLResolver <module 'million.urls' from 
'/home2/usr/public_html/websitename/app/app/million/urls.py'> 
(None:None) 'million/'>]], 'path': ''}
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
File "/home2/usr/python3.6/lib/python3.6/site-
packages/django/template/base.py", line 835, in _resolve_lookup
current = current[bit]
TypeError: 'URLResolver' object is not subscriptable
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
File "/home2/usr/python3.6/lib/python3.6/site-
packages/django/template/base.py", line 843, in _resolve_lookup
current = getattr(current, bit)
AttributeError: 'URLResolver' object has no attribute 'name'
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
File "/home2/usr/python3.6/lib/python3.6/site-
packages/django/template/base.py", line 849, in _resolve_lookup
current = current[int(bit)]
ValueError: invalid literal for int() with base 10: 'name'
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
File "/home2/usr/python3.6/lib/python3.6/site-
packages/django/template/base.py", line 856, in _resolve_lookup
(bit, current))  # missing attribute
django.template.base.VariableDoesNotExist: Failed lookup for key [name] in 
<URLResolver <module 'million.urls' from 
'/home2/usr/public_html/websitename/app/app/million/urls.py'> 
(None:None) '^million/'>
Exception while resolving variable 'name' in template 'unknown'.
Traceback (most recent call last):

Does anyone have any tips? Thank you for your time and help! I greatly appreciate it!

 

Corey

 

 


On Monday, December 25, 2017 at 10:29:23 PM UTC-6, sacrac wrote:

Hi, actually i deploy very site in bluehost with django 1.11.x and python 2.7.x and it working well but i install the flup app

for working with fastcgi in bluehost, if you show me the config with flup and version maybe help you.

 

Cheers

 

On Mon, Dec 25, 2017 at 4:14 PM, Alok Vaidya <alokva...@gmail.com> wrote:

HI All, 

 

I'm a very new into web development as well as very recently started with Python 3.6.4 and Django 2.0 and built my first web application successfully. Currently I'm in the process of deploying the web-app on a shared hosting environment on Bluehost.  

 

I was able to configure both Python and Django latest versions successfully on Bluehost server using virstualenv and was able to create my test-app ass well on the server directly using SSH client. 

 

Where I'm stuck right now is to make this app work on my domain. I have explored everything on google and tried everything possible from my side but with no luck in the end. Ever time I try to access my website in my local browser, I get the following error message: 

 

500 Server Error

A misconfiguration on the server caused a hiccup. Check the server logs, fix the problem, then try again.

 

I understand that it may not be sufficient information for anyone to help me with. I'm very new to this whole process of community and forums etc, so please let me know in case if you look for any additional info in this regard. 

 

I will greatly appreciate any help or pointing me into the right direction. 

 

Alok. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d38290f8-dd4e-4038-a958-9fed5b32fa34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



 

--

att.

Carlos Rocha

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to djang...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ab8a923c-e10f-4458-9514-2fc5bf64b982%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4b94265a-ec97-4484-9d63-2c0b3de9ef50%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment