Jump to content

Recommended Posts

Posted

Hi there:

I am writing a small wsgi framework on which il will run my website

It works on my computer, but when I upload the scripts it's not working

 

Here are the parts that I suppose are breaking it:

this is the module


class wsgiappl():		
def __call__(self, environ, start_response):
	self.environ = environ
	# post headers
	start_response("200 OK", [("Content-type", "text/html")])
	path = environ.get("PATH_INFO")
	urlpostdict = {'url':path, 'post':self.post()}
	url = self.findurl(path)
	if url == None: return "Error 404!"
	try:
		__ret = getattr(__main__, url)(urlpostdict)
	except TypeError:
		__ret = getattr(__main__, url)()

	return __ret

def findurl(self, path):
	try:
		return self.urls[path]
	except KeyError:
		for k in self.urls:
			match = re.match(k, path)
			if match != None and match == path:
				return self.urls[k]
			else:
				return None

def post(self):
	try:
		length=int(self.environ.get('CONTENT_LENGTH', '0'))
	except ValueError:
		length = 0
	if length != 0: return self.environ['wsgi.input'].read(length)
	return ""

 

and this is my index.wsgi

import cms
urls = {'/':'index'}
application = cms.wsgiappl()

 

the server has been configured so it recognises index.wsgi as an index file, and other script work fine

both the files are modded 644

 

I am getting a 500 Error and nothing else

Can anybody help? Does anybody know where the Erro Log files are?

 

 

Edit: The whole problem is caused from the import statement, see last post for more info

Posted

nope.

the typical Hello World for mod_wsgi is working fine even with a 644

is there any way I can activate a Debug instead of the 500 Error so to check for any errors or what's not working as it should?

thanks :)

 

Edit: this is the error log


[Tue Nov 15 16:51:11 2011] [error] [client 217.202.70.69]   File "/home1/torels/public_html/index.wsgi", line 2, in <module>
[Tue Nov 15 16:51:11 2011] [error] [client 217.202.70.69] mod_wsgi (pid=18981): Exception occurred processing WSGI script '/home1/torels/public_html/index.wsgi'.
[Tue Nov 15 16:51:11 2011] [error] [client 217.202.70.69] mod_wsgi (pid=18981): Target WSGI script '/home1/torels/public_html/index.wsgi' cannot be loaded as Python module.

Posted

I just realized it's depending on the import statement

it happens when I try to import a module from the same direcrory the script is in

 

so I have something like this

 

module whatever.py:

a = "whatever"
def b():
   return "whatever"

 

script:

import whatever
def application(environ, start_response):
   status = '200 OK'
   output = whatever.b()

   response_headers = [('Content-type', 'text/plain'),
                       ('Content-Length', str(len(output)))]
   start_response(status, response_headers)

   return [output]

 

This won't work and it returns a 500 error :/

Posted

On heliohost.org, it says to put this in your wsgi file:

 

import os, sys
sys.path.append("/home/your_cpanel_username/public_html/project_subdirectory");
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
os.environ['PYTHON_EGG_CACHE'] = '/home/your_cpanel_username/.python_egg_cache'

Posted

Also make sure to chmod /home/your_cpanel_username/.python_egg_cache to 777.

 

This is what I have in my wsgi file, if that helps?

 

import os, sys
sys.path.append("/home/byron/public_html/djangotest");
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
os.environ['PYTHON_EGG_CACHE'] = '/home/byron/.python_egg_cache'
## you need to create the directory above ##

import django.core.handlers.wsgi
_application = django.core.handlers.wsgi.WSGIHandler()
def application(environ, start_response):
   environ['PATH_INFO'] = environ['SCRIPT_NAME'] + environ['PATH_INFO']
   return _application(environ, start_response)

Posted

i'm not using django... It's just 2 plain WSGI files

is it the same? :/

they work when I merge them, but not if I separate them and part of it becomes a module

Posted

You can't have two *.wsgi files in your application. You can only have one *.wsgi file, and the rest of the files have to be *.py files. In addition, you must append the location of the *.py files to your pythonpath.

Posted

yeah sorry one is .wsgi and the module is .py

How do I add it to the pythonpath?

and do i have to do it even if the files are in the same directory?

Posted
How do I add it to the pythonpath?

 

 

Did you try the code I posted earlier?

 

sys.path.append("/home/your_cpanel_username/public_html/project_subdirectory");

 

 

 

 

and do i have to do it even if the files are in the same directory?

 

 

 

 

Yes. You can't expect python to magically know where your files are.

Posted

I knew it searched for modules in the module dyrectory (the pythonpath) and, if they weren't there, it moved to the directory the script was in and, just then, returned an error if the files weren't there. It works when you run it in local.

Anyway it's still not working, and i really can't figure out why

I'm still using the last scripts I posted, except for the first two lines I added:

import sys
sys.path.append("/home/torels/public_html/")

 

 

I think I will have to make some kind of import function using eval to make it work correctly :/

Posted

Perhaps if you post your username, I can look at what is causing the problem.

Posted

It probably is. Silly me, his username was right in front of me.

Guest
This topic is now closed to further replies.
×
×
  • Create New...