Getting "IndexError: list index out of range" error when running thrift example

Getting "IndexError: list index out of range" error when running thrift example

我正在尝试 运行 thrift tutorial python。但是当我尝试 运行 PythonServer.py 时,我得到这个错误:

Traceback (most recent call last):
  File "./PythonServer.py", line 24, in <module>
    sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0])
IndexError: list index out of range

我该如何解决这个问题?

每个基于 Thrift 的应用程序通常由三个部分组成,它们都是构成一个正常运行的整体所必需的:

  • 从 IDL 文件生成的代码(通过 Thrift 编译器)
  • 您的特定目标语言的 Thrift 运行时库
  • 您为实现服务器而编写的代码and/or客户端逻辑

无论您是否解压缩 runtime package from the download section of the web site, or clone Thrift from source,您总是会得到类似于此的文件夹结构1):

/
|- lib
|   |- cpp
|   |- java
|   |- py
|   +- ... more languages ...
|   
+- tutorial
    |- cpp
    |- java
    |- py
    +- ... more languages ...

文件夹 libtutorial 都包含每种语言的子目录。这就是本教程引用应该包含 Python Thrift 运行时文件的相对路径的原因。

因此,您要么想要复制相同的文件夹结构(例如,直接使用包中的教程代码),要么更改目录引用以指向 Python Thrift 运行时文件所在的文件夹实际位于。


1) 实际上,你会得到更多的文件夹,但这些在这里并不重要,所以我们忽略它们。