2012-07-18 65 views
2

我正在使用Python工具包进行拉力赛REST API来更新拉力赛服务器上的缺陷。我已经确认,我可以通过获取当前缺陷列表来与服务器进行联系并进行身份验证。我遇到了更新它们的问题。我使用Python 2.7.3与pyral 0.9.1并请求0.13.3。通过pyral更新拉力赛中的缺陷时无法分析输入流错误

此外,我正在将'verify = False'传递给Rally()调用,并已对 restapi模块进行了适当的修改以弥补这一点。

这里是我的测试代码:

import sys 
from pyral import Rally, rallySettings 

server = "rallydev.server1.com" 
user = "[email protected]" 
password = "trial" 
workspace = "trialWorkspace" 
project = "Testing Project" 
defectID = "DE192" 

rally = Rally(server, user, password, workspace=workspace, 
       project=project,  verify=False) 
defect_data = { "FormattedID" : defectID, 
       "State"  : "Closed" 
       } 
try: 
    defect = rally.update('Defect', defect_data) 
except Exception, details: 
    sys.stderr.write('ERROR: %s \n' % details) 
    sys.exit(1) 

print "Defect %s updated" % defect.FormattedID 

当我运行该脚本:

[temp]$ ./updefect.py 
ERROR: Unable to update the Defect 

如果我在RallyRESTResponse功能打印出self.errors的值更改代码的时候发现(rallyresp.py的第164行),我得到这个输出:

[temp]$ ./updefect.py 
[u"Cannot parse input stream due to I/O error as JSON document: Parse error: expected '{' but saw '\uffff' [ chars read = >>>\uffff<<< ]"] 
ERROR: Unable to update the Defect 

我确实发现了另一个问题,这可能与我的相关:
App SDK: Erorr parsing input stream when running query

你能提供任何帮助吗?

+0

我要补充一点,列出的defectID的是,我在适当的创建一个真正的缺陷真正的工作区和项目通过网络GUI。如果我在Rally调用中使用debug = on运行脚本,则可以看到POST操作期间发生的问题:https://rallydev.server1.com/slm/webservice/1.30/defe ct/12345678.js?workspace = workspace/1234&project = project/12345 – Bryon 2012-07-19 20:13:40

回答

1

将Michael关于GZIP编码的观察与另一个在这个问题上工作的支持案例的精明拉力赛客户进行了配对 - 如果内容类型没有明确定义,似乎某些版本的请求模块将默认为GZIP压缩。

解决方法是设置内容类型为application/JSON在pyral的config.py的REST头部分:

RALLY_REST_HEADERS = \ 
{ 
    'X-RallyIntegrationName'  : 'Python toolkit for Rally REST API', 
    'X-RallyIntegrationVendor' : 'Rally Software Development', 
    'X-RallyIntegrationVersion' :  '%s.%s.%s' % __version__, 
    'X-RallyIntegrationLibrary' : 'pyral-%s.%s.%s' % __version__, 
    'X-RallyIntegrationPlatform' : 'Python %s' % platform.python_version(), 
    'X-RallyIntegrationOS'  : platform.platform(), 
    'User-Agent'     : 'Pyral Rally WebServices Agent', 
    'Content-Type'    : 'application/json', 
} 
+0

就是这样!我不得不修改config.py以包含'Content-Type'这一行。没有更多的错误,我已经确认服务器上正在更新的缺陷。谢谢! – Bryon 2012-07-24 20:56:59

1

您所看到的可能与正在使用的Python 2.7.3/requests 0.13.3版本无关。您看到的错误消息也使用基于JavaScript的App SDK和用于Rally的.NET工具包(此处为2个独立报告)以及至少一个使用Python 2.6.6和请求0.9.2的人员报告。似乎在Rally WSAPI后端生成错误文字。 Rally'ers目前的评估是这是一个编码相关的问题。问题在于编码问题的起源。
我已经试过了几个版本的Python(2.6.x和2.7.x),几个版本的请求,并且在Linux,MacOS和Win7上试用过这个问题。

因为您似乎对代码潜水以及在调试模式下运行非常舒服,所以尝试的一个途径是捕获有缺陷的POST URL和POST数据,并通过基于浏览器的REST客户端尝试更新,如'Simple REST客户端“或海报,并观察您是否在WSAPI响应中收到相同的错误消息。

1

我在尝试将附件添加到缺陷时看到类似pyral的行为。

调试和日志上我看到在stdout这个请求:

2012-07-20T15:11:24.855212 PUT https://rally1.rallydev.com/slm/webservice/1.30/attachmentcontent/create.js?workspace=workspace/123456789 

然后在日志文件中的JSON:

2012-07-20 15:11:24.854 PUT attachmentcontent/create.js?workspace=workspace/123456789 
          {"AttachmentContent": {"Content": "iVBORw0KGgoAAAANSUhEUgAABBQAAAJrCAIAAADf2VflAAAXOWlDQ... 

那么这在日志文件(有点与RESTAPI激战.py解决unicode错误):

2012-07-20 15:11:25.260 404 Cannot parse input stream due to I/O error as JSON document: Parse error: expected '{' but saw '?' [ chars read = >>>?<<< ] 

值得注意的是错误代码。另外,“Can not parse input stream ...”错误信息不是来自pyral,而是来自Rally的服务器。所以派拉尔发送拉力赛拉力赛无法理解的东西。

我还记录了响应报头,其可以是线索:

{'rallyrequestid': 'qs-app-03ml3akfhdpjk7c430otjv50ak.qs-app-0387404259', 'content-encoding': 'gzip', 'transfer-encoding': 'chunked', 'expires': 'Fri, 20 Jul 2012 19:18:35 GMT', 'vary': 'Accept-Encoding', 'cache-control': 'no-cache,no-store,max-age=0,must-revalidate', 'date': 'Fri, 20 Jul 2012 19:18:36 GMT', 'p3p': 'CP="NON DSP COR CURa PSAa PSDa OUR NOR BUS PUR COM NAV STA"', 'content-type': 'text/javascript; charset=utf-8'} 

注有“内容编码”的:“gzip的”。我怀疑请求模块(我在Mac OS Python 2.6中使用0.13.3)是对它的PUT请求进行gzip编码,但Rally API服务器没有正确解码它。

+0

gzip编码的好处。 – Bryon 2012-07-24 20:58:18

相关问题