0

I didn't do the Apache setup for this it was done by the hosting company and apparently they don't know that much about Python and mod_python, so I'm stuck I only have access to a .htaccess file and my own code.

.htaccess

AddHandler python-program .py
PythonHandler wsgiref.modpython_gateway::handler
PythonOption wsgi.application code::main

code.py

#!/usr/bin/python
import web

urls = (
    '/(.*)', 'hello'
)

main = web.wsgifunc(web.webpyfunc(urls, globals()))

class hello:
    def GET(self, name):
        if not name:
            name = 'Pussy'
        return 'Hello, '+ name +'!'

#if __name__ == "__main__":
    #main = web.wsgifunc(web.webpyfunc(urls, globals()))

Error message I'm seeing when loading the code.py file

MOD_PYTHON ERROR

ProcessId:      30954
Interpreter:    'example.dk'

ServerName:     'example.dk'
DocumentRoot:   '/var/www/example.dk/web'

URI:            '/code.py'
Location:       None
Directory:      '/var/www/example.dk/web/'
Filename:       '/var/www/example.dk/web/code.py'
PathInfo:       ''

Phase:          'PythonHandler'
Handler:        'wsgiref.modpython_gateway::handler'

Traceback (most recent call last):

  File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1229, in _process_target
    result = _execute_target(config, req, object, arg)

  File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1128, in _execute_target
    result = object(arg)

  File "/usr/lib/python2.7/wsgiref/modpython_gateway.py", line 206, in handler
    app = getattr(module, objname)

AttributeError: 'module' object has no attribute 'main'

What am I missing? Im using http://webpy.org/deployment as a reference. Server environment

Linux 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) x86_64
8
  • Do you really have to use mod_python? That hasn't been the way to deploy Python apps on Apache for many years. Can you not use mod_wsgi? Commented Mar 2, 2017 at 9:01
  • You only define main if it is in the main interpreter scope (if __name__ == "__main__":) but the code module is being imported. Commented Mar 2, 2017 at 9:57
  • Daniel, mod_python is the only way with this hosting company. I could move away but they also run the mail server and other things I'd have to move as well Commented Mar 2, 2017 at 10:01
  • systemjack I changed it but still same error AttributeError: 'module' object has no attribute 'main' Commented Mar 2, 2017 at 10:05
  • webpy.org/deployment has a warning, "Be sure to visit /code.py/ with an extra / on the end. Otherwise you'll see an error message." Commented Mar 4, 2017 at 17:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.