You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Jonathan Kupferman <jk...@umail.ucsb.edu> on 2009/05/21 06:39:52 UTC
Issue with Thrift Python Bindings
Hi all,
I am trying to use the generated Python for a simple thrift file and seem to
be running into issues. I am able to generate and use the Ruby code without
a problem yet I seem to be doing something wrong with the python code.
Included below are the two thrift files used:
--------test.thrift----------
namespace py Sample
struct Name {
1: string n
}
struct User {
1: i64 id,
2: Name user_name
}
-------- end test.thrift----------
--------test_service.thrift-----------
include "test.thrift"
namespace py Sample
service TestService {
test.User get_user(1: i64 id),
test.Name get_user_name(1: i64 id),
}
--------end test_service.thrift-----------
I generate the python code using "thrift --gen py test.thrift" and then
"thrift --gen py test_service.thrift" (I've also tried recursive with the
same result). I then go in the gen-py directory and type:
>>> import Sample
>>> import Sample.ttypes
>>> from Sample import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "Sample/TestService.py", line 205, in <module>
class get_user_result:
File "Sample/TestService.py", line 212, in get_user_result
(0, TType.STRUCT, 'success', (Sample.ttypes.User,
Sample.ttypes.User.thrift_spec), None, ), # 0
AttributeError: 'module' object has no attribute 'User'
Am I doing something wrong here?
Thanks
Re: Issue with Thrift Python Bindings
Posted by David Reiss <dr...@facebook.com>.
You can't have two separate .thrift files with the same namespace,
since they will both generate ttypes files and one will clobber the
other. If this is a feature that people really want, we could probably
make this possible.
--David
Jonathan Kupferman wrote:
> Hi all,
> I am trying to use the generated Python for a simple thrift file and seem to
> be running into issues. I am able to generate and use the Ruby code without
> a problem yet I seem to be doing something wrong with the python code.
> Included below are the two thrift files used:
>
> --------test.thrift----------
> namespace py Sample
>
> struct Name {
> 1: string n
> }
>
> struct User {
> 1: i64 id,
> 2: Name user_name
> }
> -------- end test.thrift----------
>
> --------test_service.thrift-----------
>
> include "test.thrift"
>
> namespace py Sample
>
> service TestService {
> test.User get_user(1: i64 id),
> test.Name get_user_name(1: i64 id),
> }
> --------end test_service.thrift-----------
>
> I generate the python code using "thrift --gen py test.thrift" and then
> "thrift --gen py test_service.thrift" (I've also tried recursive with the
> same result). I then go in the gen-py directory and type:
>
>>>> import Sample
>>>> import Sample.ttypes
>>>> from Sample import *
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "Sample/TestService.py", line 205, in <module>
> class get_user_result:
> File "Sample/TestService.py", line 212, in get_user_result
> (0, TType.STRUCT, 'success', (Sample.ttypes.User,
> Sample.ttypes.User.thrift_spec), None, ), # 0
> AttributeError: 'module' object has no attribute 'User'
>
> Am I doing something wrong here?
>
> Thanks