not have from ladon.server.wsgi import LadonWSGIServer

Asked by romankrv on 2011-07-22

Hi. I try use your framework but i try
from ladon.server.wsgi import LadonWSGIServer
I get error because LadonWSGIServer not exist in Ladon ver 0.5x ?

What solve this problem?

Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
ladon Edit question
Assignee:
jsgaarde Edit question
Last query:
2011-07-25
Last reply:
2012-01-24

This question was reopened

jsgaarde (jakob-simon-gaarde) said : #1

Hi
I see you have followed the example from the documentation which is an old example. Some things have changed since then which is why you get the error. I will change the documentation as soon as I can. Until then I can tell you that the changes are for the better.

To test your service all you need to do now is call ladonX.Yctl. For instans if you are using Python 2.7 and have a service implemented in the script myservice.py, then you would run the command:

ladon2.7ctl serve myservice.py -p 8080

(change the "2.7" to match the Python version you are using)

This command will start your service on port 8080 If you are running Windows you might want to take a look at this stackoverflow question:
http://stackoverflow.com/questions/6637956/help-with-ladon-in-python-2-6-on-windows

Lastly there is a video tutorial that covers this topic:
http://www.youtube.com/watch?v=D_JYjEBedk4

Best regards
Jakob Simon-Gaarde

romankrv (romankrv) said : #2

ok. thanks.
also i try use as you reccomended:
i type to shell: ladontest$ ladon2.6ctl serve testservice.py -p 8080

after it i get there
Options: {'verbose': False, 'port': '8080'}
Modules: testservice.py
localhost.localdomain - - [22/Jul/2011 16:37:11] "GET / HTTP/1.1" 200 811

after there i go to firefox:
go to url: http://localhost:8080/

end I get error:

Traceback (most recent call last):
  File "/home/krv/VIRTUALENVS/testlandon/lib/python2.6/site-packages/ladon/server/wsgi_application.py", line 229, in __call__
    exec("import %s" % ','.join(self.service_list))
  File "<string>", line 1, in <module>
  File "/home/krv/stand/ladontest/testservice.py", line 5, in <module>
    class TestService(object):
  File "/home/krv/VIRTUALENVS/testlandon/lib/python2.6/site-packages/ladon/ladonizer/decorator.py", line 87, in decorator
    ladon_method_info = global_service_collection().add_service_method(f,*def_args,**def_kw)
  File "/home/krv/VIRTUALENVS/testlandon/lib/python2.6/site-packages/ladon/ladonizer/collection.py", line 116, in add_service_method
    src_fname = f.__code__.co_filename
AttributeError: type object 'TestService' has no attribute '__code__'

code testservice.py:
from ladon.ladonizer import ladonize

@ladonize(unicode, rtype=unicode)
class TestService(object):
    def helloworld(self, name):
        return "Hello %(name)s" % locals()

I use ladon 0.5.1. install it via pip install ladon

Can you help me with that problem?

Thanks

jsgaarde (jakob-simon-gaarde) said : #3

You have ladonized the whole class. You can only ladonize methods:

from ladon.ladonizer import ladonize

class TestService(object):
    @ladonize(unicode, rtype=unicode)
    def helloworld(self, name):
        return "Hello %(name)s" % locals()

romankrv (romankrv) said : #4

Ok i understand my wrong. it my spelling !!!

also are you recommended use ladon intend of soaplib? landon is more powerfull and who develop it and who use it libary too?

thanks

jsgaarde (jakob-simon-gaarde) said : #5

I develop Ladon :-) and it is active soaplib is dead as far as I can see. Also Ladon is a lot more extentable. You can make new protocols and serve your service to many protocols at once.

JSON-WSP is very effective if you are developing a service that should be accessable from a website.

/ Jakob Simon-Gaarde

romankrv (romankrv) said : #6

O great. Who help to you in develop too?

romankrv (romankrv) said : #7

Also I question is:
In docs you write

server.py:

from ladon.server.wsgi import LadonWSGIServer, LadonWSGIApplication

application = LadonWSGIApplication(['calculator'],['.'])

server = LadonWSGIServer(applications={'/': application})
server.run()

but how use this in 0.5.1 because in source Landon not have class -- >> LadonWSGIServer
How to start wsgi server?
Can you simple exapmle?

Thanks !!!

romankrv (romankrv) said : #8

Thanks jsgaarde, that solved my question.

romankrv (romankrv) said : #9

Also I question is:
In docs you write

server.py:

from ladon.server.wsgi import LadonWSGIServer, LadonWSGIApplication

application = LadonWSGIApplication(['calculator'],['.'])

server = LadonWSGIServer(applications={'/': application})
server.run()

but how use this in 0.5.1 because in source Landon not have class -- >> LadonWSGIServer
How to start wsgi server?
Could you give me simple exapmle?

Thanks !!!

jsgaarde (jakob-simon-gaarde) said : #10

> O great. Who help to you in develop too?

I am the only Ladon for Python developer for now. There is a Ladon for PHP developer too. Right now we are working on the new Ladon website:
http://ladonize.org

> but how use this in 0.5.1 because in source Landon not have class -- >> LadonWSGIServer
> How to start wsgi server?
> Could you give me simple exapmle?

Example:

from ladon.server.wsgi import LadonWSGIApplication
import wsgiref.simple_server

if __name__=='__main__':
        port = 8888
        application = LadonWSGIApplication(['calculator'],['.'])

        server = wsgiref.simple_server.make_server('',port , application)
        server.serve_forever()

But... You should only use this method and ladonX.Yctl to test your service. When you go in production you should use a real webserver. As shown in example 2 in the docs:
http://packages.python.org/ladon/#example-2

romankrv (romankrv) said : #11

Ok thanks for answer.

Could you explain why I get error :

Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/ladon/server/wsgi_application.py", line 229, in __call__
    exec("import %s" % ','.join(self.service_list))
  File "<string>", line 1, in <module>
ImportError: No module named SessionService

my code is (where I get error):

from ladon.ladonizer import ladonize
class SessionService(object):
    @ladonize(str,str,rtype=str)
    def login(self,username,password):
        session_id = '111'
        return session_id

from ladon.server.wsgi import LadonWSGIApplication
import wsgiref.simple_server

if __name__=='__main__':
       port = 8889
       application = LadonWSGIApplication(['SessionService'],['.'])

       server = wsgiref.simple_server.make_server('',port , application)
       server.serve_forever()

Thanks

jsgaarde (jakob-simon-gaarde) said : #12

Hi Romankrv.

I am guesseing that you servicemodule is not called SessionService.py (capital S). If the module filename is sessionservice.py then you must write ' sessionservice' when you create the LadonWSGIApplication object.

Best regards
Jakob Simon-Gaarde

jsgaarde (jakob-simon-gaarde) said : #13

And the last one :-)

jsgaarde (jakob-simon-gaarde) said : #14

Setting to solved, so other people can benefit from the info.