使用tcms_api与我们的Kiwi部署中的API通信时遇到问题。
尝试执行此脚本(test_kiwi_api.py),取自在线某个地方的示例:
import tcms_api
rpc_client = tcms_api.TCMS().exec
for test_case in rpc_client.exec.TestCase.filter({'pk': 46490}):
print(test_case)
按照tcms-api 5.3 package incompatible with Windows的步骤更改为kerberos-sspi(并安装Kerberos for Windows和kerberos-sspi python软件包)之后, 遇到此错误:
C:\ kiwi \ api>。\ test_kiwi_api.py
Traceback (most recent call last):
File "C:\kiwi\api\test_kiwi_api.py", line 1, in <module>
import tcms_api
File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\tcms_api\__init__.py", line 64, in <module>
from .xmlrpc import TCMSXmlrpc, TCMSKerbXmlrpc
File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\tcms_api\xmlrpc.py", line 22, in <module>
import kerberos as k
ModuleNotFoundError: No module named 'kerberos'
直接编辑xmlrpc.py后,使其使用kerberos-sspi而不是kerberos
通过更改完成:
import kerberos
收件人:
try:
import kerberos as k
except:
import kerberos_sspi as k
...并将以后的kerberos引用更改为k个引用
遇到此错误:
C:\ kiwi \ api>。\ test_kiwi_api.py
File "C:\kiwi\api\test_kiwi_api.py", line 2, in <module>
rpc_client = tcms_api.TCMS().exec
File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\tcms_api\__init__.py", line 99, in __init__
TCMS._connection = TCMSKerbXmlrpc(config['tcms']['url']).server
File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\tcms_api\xmlrpc.py", line 142, in __init__
self.server.Auth.login_krbv()
File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 1112, in __call__
return self.__send(self.__name, args)
File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 1452, in __request
verbose=self.__verbose
File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 1154, in request
return self.single_request(host, handler, request_body, verbose)
File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 1166, in single_request
http_conn = self.send_request(host, handler, request_body, verbose)
File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\xmlrpc\client.py", line 1267, in send_request
connection = self.make_connection(host)
File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\tcms_api\xmlrpc.py", line 79, in make_connection
chost, self._extra_headers, x509 = self.get_host_info(host)
File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\tcms_api\xmlrpc.py", line 64, in get_host_info
k.authGSSClientStep(context, "")
File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\kerberos_sspi.py", line 218, in authGSSClientStep
err, sec_buffer = context["csa"].authorize(data)
File "C:\Users\rfeldman\AppData\Local\Programs\Python\Python37\lib\site-packages\win32\lib\sspi.py", line 139, in authorize
sec_buffer_out)
pywintypes.error: (-2146893053, 'InitializeSecurityContext', 'The specified target is unknown or unreachable')
我研究的只是编写一个node.js API接口(因为这里的大多数开发工作都是在node上完成的,如果需要的话可以得到开发帮助会很好),但是一项小小的研究表明,他们的kerberos软件包依赖于Python,所以我很确定我也会在这里遇到这个问题。 如果我可以编写(node.js tcms_api接口)但使用除kerberos之外的其他东西进行连接,则可以尝试一下,并在可以使用的情况下共享它。
编辑:这是我的配置文件(在Windows中为C:\ etc)
[tcms]
url = https://qaportal01.irvl.mymbnet.com/xml-rpc/
username = rfeldman
password = <not shown>
use_mod_kerb = False
答案 0 :(得分:0)
结果证明这是配置处理方式中的实际错误。即使将use_mod_kerb设置为False,返回的值也是字符串类型(“ False”),Python始终在布尔上下文中将其评估为True(任何非空字符串均评估为True)。
已通过在评估之前将config值转换为bool值来解决此问题: https://github.com/kiwitcms/tcms-api/pull/11,并已在tcms-api版本6.7.1中发布