500 error with object in list

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

500 error with object in list

Ben Marinic
Hello again!

What am I doing wrong here?  I create my list which contains an object.  I can instantiate and get this object in the shell (see below).  But when I request it either through my Flex client or the Python client it gives me a 500 error (below) - is this an encoding issue?  Should I be using some other array type i.e. PyAMF ArrayCollection?  A list with strings is working OK.  

Thanks
Ben

-client.py

import sys

sys.path.append('/usr/src/pyamf/')

from pyamf.remoting.client import RemotingService


echo_service = gateway.getService('echo')
clients_service = gateway.getService('getClients')

print echo_service('Hello world!')

print clients_service()[0].name


-contoller.py

from model import Client, Skill
class ClientsControl(object):

    def __init__(self):
        self.myList = ["1","2","3"]
        self.myList.append("4")
        self.myClients = []
        self.myClients.append(Client("client", "ria project", [Skill("flex"), Skill("streaming video")], "website.co.uk"))

    def echo(self,data):
        return data

    def getClients(self):
        return self.myClients // this doesn't work
#return self.myList // this does work


-LOG:

Hello world!
Traceback (most recent call last):
  File "client.py", line 14, in <module>
    print clients_service()[0].name
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 116, in __call__
    """
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 105, in _call
    Raised if the element could not be encoded to the stream.
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 424, in execute_single
    if not self.exclude_attrs:
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 476, in _getResponse
    if self.encodable_properties or self.static_attrs or self.exclude_attrs:
pyamf.remoting.RemotingError: HTTP Gateway reported status 500 Internal Server Error



-SHELL:

>>> import sys
>>> sys.path.append('/var/www/combinationStudiosWebsite/')
>>> import controller
>>> myc = controller.ClientsControl()
>>> myc
<controller.ClientsControl object at 0xb75cd98c>
>>> myc.getClients()
[<model.Client object at 0xb75cdb6c>]
>>> myc.getClients()[0].name
'client'
>>> 



Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159





_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: 500 error with object in list

Nick Joyce
On 2 Dec 2009, at 20:51, Ben Marinic wrote:

Hello again!

What am I doing wrong here?  I create my list which contains an object.  I can instantiate and get this object in the shell (see below).  But when I request it either through my Flex client or the Python client it gives me a 500 error (below) - is this an encoding issue?  Should I be using some other array type i.e. PyAMF ArrayCollection?  A list with strings is working OK.  

Thanks
Ben

-client.py

import sys

sys.path.append('/usr/src/pyamf/')

from pyamf.remoting.client import RemotingService


echo_service = gateway.getService('echo')
clients_service = gateway.getService('getClients')

print echo_service('Hello world!')

print clients_service()[0].name


-contoller.py

from model import Client, Skill
class ClientsControl(object):

    def __init__(self):
        self.myList = ["1","2","3"]
        self.myList.append("4")
        self.myClients = []
        self.myClients.append(Client("client", "ria project", [Skill("flex"), Skill("streaming video")], "website.co.uk"))

    def echo(self,data):
        return data

    def getClients(self):
        return self.myClients // this doesn't work
#return self.myList // this does work


-LOG:

Hello world!
Traceback (most recent call last):
  File "client.py", line 14, in <module>
    print clients_service()[0].name
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 116, in __call__
    """
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 105, in _call
    Raised if the element could not be encoded to the stream.
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 424, in execute_single
    if not self.exclude_attrs:
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 476, in _getResponse
    if self.encodable_properties or self.static_attrs or self.exclude_attrs:
pyamf.remoting.RemotingError: HTTP Gateway reported status 500 Internal Server Error

That doesn't appear to be the complete log, can you double check ? Could you also attach the server error log for this,  if any - that would be useful too..

Thanks!




-SHELL:

>>> import sys
>>> sys.path.append('/var/www/combinationStudiosWebsite/')
>>> import controller
>>> myc = controller.ClientsControl()
>>> myc
<controller.ClientsControl object at 0xb75cd98c>
>>> myc.getClients()
[<model.Client object at 0xb75cdb6c>]
>>> myc.getClients()[0].name
'client'
>>> 



Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159




_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: 500 error with object in list

Ben Marinic
Hi Nick

Sorry I meant the stack trace not log.  But here is the log.

Thanks
Ben

This is all I get back (main Apache and virtual host logs combined INFO level):

[02/Dec/2009:22:19:20 +0000] "POST /gateway HTTP/1.1" 500 2159 "-" "PyAMF/0.5.1" 

[Wed Dec 02 22:16:25 2009] [info] [client 69.164.211.82] mod_wsgi (pid=30774, process='', application='flashservices.combinationstudios.com|/gateway'): Loading WSGI script '/var/www/combinationStudiosWebsite/startup.py'.

[Wed Dec 02 22:19:20 2009] [error]     func(data)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/amf0.py", line 690, in writeObject
[Wed Dec 02 22:19:20 2009] [error]     alias = self.context.getClassAlias(o.__class__)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/__init__.py", line 232, in getClassAlias
[Wed Dec 02 22:19:20 2009] [error]     self.class_aliases[klass] = alias(klass)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/__init__.py", line 288, in __init__
[Wed Dec 02 22:19:20 2009] [error]     self.checkClass(klass)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/__init__.py", line 570, in checkClass
[Wed Dec 02 22:19:20 2009] [error]     % sign)
[Wed Dec 02 22:19:20 2009] [error] TypeError: __init__ doesn't support additional arguments: Client.__init__(self, name, title, skills, url)



On 2 Dec 2009, at 21:11, Nick Joyce wrote:

On 2 Dec 2009, at 20:51, Ben Marinic wrote:

Hello again!

What am I doing wrong here?  I create my list which contains an object.  I can instantiate and get this object in the shell (see below).  But when I request it either through my Flex client or the Python client it gives me a 500 error (below) - is this an encoding issue?  Should I be using some other array type i.e. PyAMF ArrayCollection?  A list with strings is working OK.  

Thanks
Ben

-client.py

import sys

sys.path.append('/usr/src/pyamf/')

from pyamf.remoting.client import RemotingService


echo_service = gateway.getService('echo')
clients_service = gateway.getService('getClients')

print echo_service('Hello world!')

print clients_service()[0].name


-contoller.py

from model import Client, Skill
class ClientsControl(object):

    def __init__(self):
        self.myList = ["1","2","3"]
        self.myList.append("4")
        self.myClients = []
        self.myClients.append(Client("client", "ria project", [Skill("flex"), Skill("streaming video")], "website.co.uk"))

    def echo(self,data):
        return data

    def getClients(self):
        return self.myClients // this doesn't work
#return self.myList // this does work


-LOG:

Hello world!
Traceback (most recent call last):
  File "client.py", line 14, in <module>
    print clients_service()[0].name
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 116, in __call__
    """
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 105, in _call
    Raised if the element could not be encoded to the stream.
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 424, in execute_single
    if not self.exclude_attrs:
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 476, in _getResponse
    if self.encodable_properties or self.static_attrs or self.exclude_attrs:
pyamf.remoting.RemotingError: HTTP Gateway reported status 500 Internal Server Error

That doesn't appear to be the complete log, can you double check ? Could you also attach the server error log for this,  if any - that would be useful too..

Thanks!




-SHELL:

>>> import sys
>>> sys.path.append('/var/www/combinationStudiosWebsite/')
>>> import controller
>>> myc = controller.ClientsControl()
>>> myc
<controller.ClientsControl object at 0xb75cd98c>
>>> myc.getClients()
[<model.Client object at 0xb75cdb6c>]
>>> myc.getClients()[0].name
'client'
>>> 



Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159




_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159





_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: 500 error with object in list

Nick Joyce
So the issue here is that PyAMF is complaining about the declaration of the Client class.

Since PyAMF (potentially) needs to be able to create instances of Client when decoding requests, it can't do so (at least not automatically) with args required __init__.

Right now, if you want to keep the __init__ args you would need to do the following:

import pyamf

class Client(object):
    def __init__(self, name, title, skills, url):
        pass

class ClientClassAlias(pyamf.ClassAlias):
    def checkClass(self, klass):
        pass

pyamf.register_alias_type(Client, ClientClassAlias)

Which is a little crazy! :) There is some work going on towards resolving this, see http://pyamf.org/ticket/700

Cheers,

Nick

On 2 Dec 2009, at 22:25, Ben Marinic wrote:

Hi Nick

Sorry I meant the stack trace not log.  But here is the log.

Thanks
Ben

This is all I get back (main Apache and virtual host logs combined INFO level):

[02/Dec/2009:22:19:20 +0000] "POST /gateway HTTP/1.1" 500 2159 "-" "PyAMF/0.5.1" 

[Wed Dec 02 22:16:25 2009] [info] [client 69.164.211.82] mod_wsgi (pid=30774, process='', application='flashservices.combinationstudios.com|/gateway'): Loading WSGI script '/var/www/combinationStudiosWebsite/startup.py'.

[Wed Dec 02 22:19:20 2009] [error]     func(data)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/amf0.py", line 690, in writeObject
[Wed Dec 02 22:19:20 2009] [error]     alias = self.context.getClassAlias(o.__class__)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/__init__.py", line 232, in getClassAlias
[Wed Dec 02 22:19:20 2009] [error]     self.class_aliases[klass] = alias(klass)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/__init__.py", line 288, in __init__
[Wed Dec 02 22:19:20 2009] [error]     self.checkClass(klass)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/__init__.py", line 570, in checkClass
[Wed Dec 02 22:19:20 2009] [error]     % sign)
[Wed Dec 02 22:19:20 2009] [error] TypeError: __init__ doesn't support additional arguments: Client.__init__(self, name, title, skills, url)



On 2 Dec 2009, at 21:11, Nick Joyce wrote:

On 2 Dec 2009, at 20:51, Ben Marinic wrote:

Hello again!

What am I doing wrong here?  I create my list which contains an object.  I can instantiate and get this object in the shell (see below).  But when I request it either through my Flex client or the Python client it gives me a 500 error (below) - is this an encoding issue?  Should I be using some other array type i.e. PyAMF ArrayCollection?  A list with strings is working OK.  

Thanks
Ben

-client.py

import sys

sys.path.append('/usr/src/pyamf/')

from pyamf.remoting.client import RemotingService


echo_service = gateway.getService('echo')
clients_service = gateway.getService('getClients')

print echo_service('Hello world!')

print clients_service()[0].name


-contoller.py

from model import Client, Skill
class ClientsControl(object):

    def __init__(self):
        self.myList = ["1","2","3"]
        self.myList.append("4")
        self.myClients = []
        self.myClients.append(Client("client", "ria project", [Skill("flex"), Skill("streaming video")], "website.co.uk"))

    def echo(self,data):
        return data

    def getClients(self):
        return self.myClients // this doesn't work
#return self.myList // this does work


-LOG:

Hello world!
Traceback (most recent call last):
  File "client.py", line 14, in <module>
    print clients_service()[0].name
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 116, in __call__
    """
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 105, in _call
    Raised if the element could not be encoded to the stream.
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 424, in execute_single
    if not self.exclude_attrs:
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 476, in _getResponse
    if self.encodable_properties or self.static_attrs or self.exclude_attrs:
pyamf.remoting.RemotingError: HTTP Gateway reported status 500 Internal Server Error

That doesn't appear to be the complete log, can you double check ? Could you also attach the server error log for this,  if any - that would be useful too..

Thanks!




-SHELL:

>>> import sys
>>> sys.path.append('/var/www/combinationStudiosWebsite/')
>>> import controller
>>> myc = controller.ClientsControl()
>>> myc
<controller.ClientsControl object at 0xb75cd98c>
>>> myc.getClients()
[<model.Client object at 0xb75cdb6c>]
>>> myc.getClients()[0].name
'client'
>>> 



Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159




_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159




_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: 500 error with object in list

Ben Marinic
Thanks Nick.

Is there some other way I can intiantiate my models without polluting them with PyAMF specific code?  

Ben  

On 3 Dec 2009, at 11:13, Nick Joyce wrote:

So the issue here is that PyAMF is complaining about the declaration of the Client class.

Since PyAMF (potentially) needs to be able to create instances of Client when decoding requests, it can't do so (at least not automatically) with args required __init__.

Right now, if you want to keep the __init__ args you would need to do the following:

import pyamf

class Client(object):
    def __init__(self, name, title, skills, url):
        pass

class ClientClassAlias(pyamf.ClassAlias):
    def checkClass(self, klass):
        pass

pyamf.register_alias_type(Client, ClientClassAlias)

Which is a little crazy! :) There is some work going on towards resolving this, see http://pyamf.org/ticket/700

Cheers,

Nick

On 2 Dec 2009, at 22:25, Ben Marinic wrote:

Hi Nick

Sorry I meant the stack trace not log.  But here is the log.

Thanks
Ben

This is all I get back (main Apache and virtual host logs combined INFO level):

[02/Dec/2009:22:19:20 +0000] "POST /gateway HTTP/1.1" 500 2159 "-" "PyAMF/0.5.1" 

[Wed Dec 02 22:16:25 2009] [info] [client 69.164.211.82] mod_wsgi (pid=30774, process='', application='flashservices.combinationstudios.com|/gateway'): Loading WSGI script '/var/www/combinationStudiosWebsite/startup.py'.

[Wed Dec 02 22:19:20 2009] [error]     func(data)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/amf0.py", line 690, in writeObject
[Wed Dec 02 22:19:20 2009] [error]     alias = self.context.getClassAlias(o.__class__)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/__init__.py", line 232, in getClassAlias
[Wed Dec 02 22:19:20 2009] [error]     self.class_aliases[klass] = alias(klass)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/__init__.py", line 288, in __init__
[Wed Dec 02 22:19:20 2009] [error]     self.checkClass(klass)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/__init__.py", line 570, in checkClass
[Wed Dec 02 22:19:20 2009] [error]     % sign)
[Wed Dec 02 22:19:20 2009] [error] TypeError: __init__ doesn't support additional arguments: Client.__init__(self, name, title, skills, url)



On 2 Dec 2009, at 21:11, Nick Joyce wrote:

On 2 Dec 2009, at 20:51, Ben Marinic wrote:

Hello again!

What am I doing wrong here?  I create my list which contains an object.  I can instantiate and get this object in the shell (see below).  But when I request it either through my Flex client or the Python client it gives me a 500 error (below) - is this an encoding issue?  Should I be using some other array type i.e. PyAMF ArrayCollection?  A list with strings is working OK.  

Thanks
Ben

-client.py

import sys

sys.path.append('/usr/src/pyamf/')

from pyamf.remoting.client import RemotingService


echo_service = gateway.getService('echo')
clients_service = gateway.getService('getClients')

print echo_service('Hello world!')

print clients_service()[0].name


-contoller.py

from model import Client, Skill
class ClientsControl(object):

    def __init__(self):
        self.myList = ["1","2","3"]
        self.myList.append("4")
        self.myClients = []
        self.myClients.append(Client("client", "ria project", [Skill("flex"), Skill("streaming video")], "website.co.uk"))

    def echo(self,data):
        return data

    def getClients(self):
        return self.myClients // this doesn't work
#return self.myList // this does work


-LOG:

Hello world!
Traceback (most recent call last):
  File "client.py", line 14, in <module>
    print clients_service()[0].name
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 116, in __call__
    """
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 105, in _call
    Raised if the element could not be encoded to the stream.
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 424, in execute_single
    if not self.exclude_attrs:
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 476, in _getResponse
    if self.encodable_properties or self.static_attrs or self.exclude_attrs:
pyamf.remoting.RemotingError: HTTP Gateway reported status 500 Internal Server Error

That doesn't appear to be the complete log, can you double check ? Could you also attach the server error log for this,  if any - that would be useful too..

Thanks!




-SHELL:

>>> import sys
>>> sys.path.append('/var/www/combinationStudiosWebsite/')
>>> import controller
>>> myc = controller.ClientsControl()
>>> myc
<controller.ClientsControl object at 0xb75cd98c>
>>> myc.getClients()
[<model.Client object at 0xb75cdb6c>]
>>> myc.getClients()[0].name
'client'
>>> 



Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159




_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159




_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159





_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: 500 error with object in list

Nick Joyce
Right now the easiest thing to do would be to refactor Client to not require __init__ args, or do some python ninjutsu like so:

class Client(object):
    def __init__(self, *args):
        name, title, skills, url = args

        # more here

If you can, the first would probably be preferable.

Hth,

Nick

On 3 Dec 2009, at 12:14, Ben Marinic wrote:

Thanks Nick.

Is there some other way I can intiantiate my models without polluting them with PyAMF specific code?  

Ben  

On 3 Dec 2009, at 11:13, Nick Joyce wrote:

So the issue here is that PyAMF is complaining about the declaration of the Client class.

Since PyAMF (potentially) needs to be able to create instances of Client when decoding requests, it can't do so (at least not automatically) with args required __init__.

Right now, if you want to keep the __init__ args you would need to do the following:

import pyamf

class Client(object):
    def __init__(self, name, title, skills, url):
        pass

class ClientClassAlias(pyamf.ClassAlias):
    def checkClass(self, klass):
        pass

pyamf.register_alias_type(Client, ClientClassAlias)

Which is a little crazy! :) There is some work going on towards resolving this, see http://pyamf.org/ticket/700

Cheers,

Nick

On 2 Dec 2009, at 22:25, Ben Marinic wrote:

Hi Nick

Sorry I meant the stack trace not log.  But here is the log.

Thanks
Ben

This is all I get back (main Apache and virtual host logs combined INFO level):

[02/Dec/2009:22:19:20 +0000] "POST /gateway HTTP/1.1" 500 2159 "-" "PyAMF/0.5.1" 

[Wed Dec 02 22:16:25 2009] [info] [client 69.164.211.82] mod_wsgi (pid=30774, process='', application='flashservices.combinationstudios.com|/gateway'): Loading WSGI script '/var/www/combinationStudiosWebsite/startup.py'.

[Wed Dec 02 22:19:20 2009] [error]     func(data)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/amf0.py", line 690, in writeObject
[Wed Dec 02 22:19:20 2009] [error]     alias = self.context.getClassAlias(o.__class__)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/__init__.py", line 232, in getClassAlias
[Wed Dec 02 22:19:20 2009] [error]     self.class_aliases[klass] = alias(klass)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/__init__.py", line 288, in __init__
[Wed Dec 02 22:19:20 2009] [error]     self.checkClass(klass)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/__init__.py", line 570, in checkClass
[Wed Dec 02 22:19:20 2009] [error]     % sign)
[Wed Dec 02 22:19:20 2009] [error] TypeError: __init__ doesn't support additional arguments: Client.__init__(self, name, title, skills, url)



On 2 Dec 2009, at 21:11, Nick Joyce wrote:

On 2 Dec 2009, at 20:51, Ben Marinic wrote:

Hello again!

What am I doing wrong here?  I create my list which contains an object.  I can instantiate and get this object in the shell (see below).  But when I request it either through my Flex client or the Python client it gives me a 500 error (below) - is this an encoding issue?  Should I be using some other array type i.e. PyAMF ArrayCollection?  A list with strings is working OK.  

Thanks
Ben

-client.py

import sys

sys.path.append('/usr/src/pyamf/')

from pyamf.remoting.client import RemotingService


echo_service = gateway.getService('echo')
clients_service = gateway.getService('getClients')

print echo_service('Hello world!')

print clients_service()[0].name


-contoller.py

from model import Client, Skill
class ClientsControl(object):

    def __init__(self):
        self.myList = ["1","2","3"]
        self.myList.append("4")
        self.myClients = []
        self.myClients.append(Client("client", "ria project", [Skill("flex"), Skill("streaming video")], "website.co.uk"))

    def echo(self,data):
        return data

    def getClients(self):
        return self.myClients // this doesn't work
#return self.myList // this does work


-LOG:

Hello world!
Traceback (most recent call last):
  File "client.py", line 14, in <module>
    print clients_service()[0].name
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 116, in __call__
    """
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 105, in _call
    Raised if the element could not be encoded to the stream.
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 424, in execute_single
    if not self.exclude_attrs:
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 476, in _getResponse
    if self.encodable_properties or self.static_attrs or self.exclude_attrs:
pyamf.remoting.RemotingError: HTTP Gateway reported status 500 Internal Server Error

That doesn't appear to be the complete log, can you double check ? Could you also attach the server error log for this,  if any - that would be useful too..

Thanks!




-SHELL:

>>> import sys
>>> sys.path.append('/var/www/combinationStudiosWebsite/')
>>> import controller
>>> myc = controller.ClientsControl()
>>> myc
<controller.ClientsControl object at 0xb75cd98c>
>>> myc.getClients()
[<model.Client object at 0xb75cdb6c>]
>>> myc.getClients()[0].name
'client'
>>> 



Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159




_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159




_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159




_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: 500 error with object in list

Ben Marinic
Thanks Nick.  I refactored per your recommendation and all is good again.  It took a while (between installation issues, python egg path issues, wrong import ordering and the constructor args problem), but I now have end to end!!  Will have to put this in a blog for my own reference at the very least..  Phew!

Cheers
Ben


On 3 Dec 2009, at 13:06, Nick Joyce wrote:

Right now the easiest thing to do would be to refactor Client to not require __init__ args, or do some python ninjutsu like so:

class Client(object):
    def __init__(self, *args):
        name, title, skills, url = args

        # more here

If you can, the first would probably be preferable.

Hth,

Nick

On 3 Dec 2009, at 12:14, Ben Marinic wrote:

Thanks Nick.

Is there some other way I can intiantiate my models without polluting them with PyAMF specific code?  

Ben  

On 3 Dec 2009, at 11:13, Nick Joyce wrote:

So the issue here is that PyAMF is complaining about the declaration of the Client class.

Since PyAMF (potentially) needs to be able to create instances of Client when decoding requests, it can't do so (at least not automatically) with args required __init__.

Right now, if you want to keep the __init__ args you would need to do the following:

import pyamf

class Client(object):
    def __init__(self, name, title, skills, url):
        pass

class ClientClassAlias(pyamf.ClassAlias):
    def checkClass(self, klass):
        pass

pyamf.register_alias_type(Client, ClientClassAlias)

Which is a little crazy! :) There is some work going on towards resolving this, see http://pyamf.org/ticket/700

Cheers,

Nick

On 2 Dec 2009, at 22:25, Ben Marinic wrote:

Hi Nick

Sorry I meant the stack trace not log.  But here is the log.

Thanks
Ben

This is all I get back (main Apache and virtual host logs combined INFO level):

[02/Dec/2009:22:19:20 +0000] "POST /gateway HTTP/1.1" 500 2159 "-" "PyAMF/0.5.1" 

[Wed Dec 02 22:16:25 2009] [info] [client 69.164.211.82] mod_wsgi (pid=30774, process='', application='flashservices.combinationstudios.com|/gateway'): Loading WSGI script '/var/www/combinationStudiosWebsite/startup.py'.

[Wed Dec 02 22:19:20 2009] [error]     func(data)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/amf0.py", line 690, in writeObject
[Wed Dec 02 22:19:20 2009] [error]     alias = self.context.getClassAlias(o.__class__)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/__init__.py", line 232, in getClassAlias
[Wed Dec 02 22:19:20 2009] [error]     self.class_aliases[klass] = alias(klass)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/__init__.py", line 288, in __init__
[Wed Dec 02 22:19:20 2009] [error]     self.checkClass(klass)
[Wed Dec 02 22:19:20 2009] [error]   File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/__init__.py", line 570, in checkClass
[Wed Dec 02 22:19:20 2009] [error]     % sign)
[Wed Dec 02 22:19:20 2009] [error] TypeError: __init__ doesn't support additional arguments: Client.__init__(self, name, title, skills, url)



On 2 Dec 2009, at 21:11, Nick Joyce wrote:

On 2 Dec 2009, at 20:51, Ben Marinic wrote:

Hello again!

What am I doing wrong here?  I create my list which contains an object.  I can instantiate and get this object in the shell (see below).  But when I request it either through my Flex client or the Python client it gives me a 500 error (below) - is this an encoding issue?  Should I be using some other array type i.e. PyAMF ArrayCollection?  A list with strings is working OK.  

Thanks
Ben

-client.py

import sys

sys.path.append('/usr/src/pyamf/')

from pyamf.remoting.client import RemotingService


echo_service = gateway.getService('echo')
clients_service = gateway.getService('getClients')

print echo_service('Hello world!')

print clients_service()[0].name


-contoller.py

from model import Client, Skill
class ClientsControl(object):

    def __init__(self):
        self.myList = ["1","2","3"]
        self.myList.append("4")
        self.myClients = []
        self.myClients.append(Client("client", "ria project", [Skill("flex"), Skill("streaming video")], "website.co.uk"))

    def echo(self,data):
        return data

    def getClients(self):
        return self.myClients // this doesn't work
#return self.myList // this does work


-LOG:

Hello world!
Traceback (most recent call last):
  File "client.py", line 14, in <module>
    print clients_service()[0].name
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 116, in __call__
    """
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 105, in _call
    Raised if the element could not be encoded to the stream.
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 424, in execute_single
    if not self.exclude_attrs:
  File "/usr/local/lib/python2.6/dist-packages/PyAMF-0.5.1-py2.6-linux-i686.egg/pyamf/remoting/client/__init__.py", line 476, in _getResponse
    if self.encodable_properties or self.static_attrs or self.exclude_attrs:
pyamf.remoting.RemotingError: HTTP Gateway reported status 500 Internal Server Error

That doesn't appear to be the complete log, can you double check ? Could you also attach the server error log for this,  if any - that would be useful too..

Thanks!




-SHELL:

>>> import sys
>>> sys.path.append('/var/www/combinationStudiosWebsite/')
>>> import controller
>>> myc = controller.ClientsControl()
>>> myc
<controller.ClientsControl object at 0xb75cd98c>
>>> myc.getClients()
[<model.Client object at 0xb75cdb6c>]
>>> myc.getClients()[0].name
'client'
>>> 



Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159




_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159




_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159




_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users

Ben Marinic
Combination Studios Ltd
t. +44 (0)7813 147 159





_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users