torels2 Posted November 15, 2011 Posted November 15, 2011 Hi there:I am writing a small wsgi framework on which il will run my websiteIt 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 fineboth the files are modded 644 I am getting a 500 Error and nothing elseCan 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
torels2 Posted November 15, 2011 Author Posted November 15, 2011 nope.the typical Hello World for mod_wsgi is working fine even with a 644is 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.
torels2 Posted November 15, 2011 Author Posted November 15, 2011 I just realized it's depending on the import statementit 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 :/
Guest xaav Posted November 16, 2011 Posted November 16, 2011 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'
Byron Posted November 16, 2011 Posted November 16, 2011 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)
torels2 Posted November 16, 2011 Author Posted November 16, 2011 i'm not using django... It's just 2 plain WSGI filesis it the same? :/they work when I merge them, but not if I separate them and part of it becomes a module
Guest xaav Posted November 16, 2011 Posted November 16, 2011 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.
torels2 Posted November 17, 2011 Author Posted November 17, 2011 yeah sorry one is .wsgi and the module is .pyHow do I add it to the pythonpath?and do i have to do it even if the files are in the same directory?
Guest xaav Posted November 18, 2011 Posted November 18, 2011 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.
torels2 Posted November 18, 2011 Author Posted November 18, 2011 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 whyI'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 :/
Guest xaav Posted November 19, 2011 Posted November 19, 2011 Perhaps if you post your username, I can look at what is causing the problem.
Krydos Posted November 19, 2011 Posted November 19, 2011 username: torelsserver: stevie /home/torels/ doesn't exist, but /home1/torels/ does. That's probably the issue, eh?
Guest xaav Posted November 19, 2011 Posted November 19, 2011 It probably is. Silly me, his username was right in front of me.
Recommended Posts