Run Python-Thrift demo

Source: Internet
Author: User

Start servers and clients

 
Cd ~ /Thrift-0.8.0/Thrift-R --Gen py tutorial. Thrift # generateCodeCD py./Pythonserver. py # Start the server CD~ /Thrift-0.8.0/Py./Pythonclient. py # Start the client in another shell window

 

As a result, an error occurs when the server is started.

Shujunli @ mysvr1 :~ /Thrift- 0.8 . 0 /Tutorial/Py $ ./ Pythonserver. py starting the server... traceback (most recent call  Last ): File  "  ./Pythonserver. py  " , Line 95 , In <Module> Server. Serve () File  "  /Usr/lib/python2.7/Site-packages/thrift/Server/tserver. py  " , Line 74 , In  Serve self. servertransport. Listen () File  " /Usr/lib/python2.7/Site-packages/thrift/transport/tsocket. py  " , Line 136 , In  Listen res0 = Self. _ resolveaddr () File  "  /Usr/lib/python2.7/Site-packages/thrift/transport/tsocket. py  " , Line 31 , In  _ Resolveaddr return socket. getaddrinfo (self. Host, self. Port, socket. af_unspec, socket. sock_stream, 0 , Socket. ai_passive | Socket. ai_addrconfig) typeerror: getaddrinfo () argument  1 Must be String Or none

Let's take a look at file "pythonserver. py" and line 95.

 
Transport = tsocket. tserversocket (9090)

Let's look at the tserversocket source code

 
Def _ Init __(Self, host = none, Port = 9090, unix_socket = none ):

This is because of its initialization function. The first parameter is host, and the second parameter is port. Therefore, it is not feasible to save host. PY ", line 95 changed:

 
Transport = tsocket. tserversocket ('Localhost', 9090)

Or

 
Transport = tsocket. tserversocket (Port = 9090)

To solve the problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.