通过 pyral 更新 Rally 中的缺陷时出现"无法解析输入流"错误



我正在使用Python Toolkit for Rally REST API来更新我们Rally服务器上的缺陷。我已经确认,我能够与服务器取得联系,并通过获取当前缺陷列表进行身份验证。我在更新它们时遇到了问题。我使用Python2.7.3,pyral0.9.1,请求0.13.3。

此外,我正在向Rally()调用传递"verify=False",并对restapi模块对此进行补偿。

这是我的测试代码:

import sys
from pyral import Rally, rallySettings
server = "rallydev.server1.com"
user = "user@mycompany.com"
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  

如果我更改Rally RESTRESponse函数中的代码,以在找到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  

我确实在这里找到了另一个听起来可能与我有关的问题:
应用程序SDK:运行查询时Erorr解析输入流

你能提供任何帮助吗?

将Michael关于GZIP编码的观察结果与另一位精明的Rally客户在该问题上处理支持案例的观察结果进行对比-如果没有具体定义内容类型,则某些版本的请求模块将默认为GZIP压缩。

修复方法是在pyral的config.py:的RESTHeaders部分将内容类型设置为application/json

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',
}

您所看到的可能与正在使用的Python 2.7.3/请求0.13.3版本无关。您看到的错误消息也是使用基于Javascript的App SDK和.NET Toolkit for Rally(SO上有两个单独的报告)以及至少一个使用Python 2.6.6和请求0.9.2的其他人报告的。错误措辞似乎是在Rally WSAPI后端生成的。目前,其他拉力赛选手的评估是,这是一个与编码相关的问题。问题是编码问题的根源
我已经尝试了几个版本的Python(2.6.x和2.7.x)、几个版本的请求以及Linux、MacOS和Win7,但我还无法重新解决这个问题。

由于您似乎对深入代码并在调试模式下运行非常满意,因此尝试的一种方法是捕获有缺陷的POST URL和POST数据,并尝试通过基于浏览器的REST客户端(如"简单REST客户端"或Poster)进行更新,并观察WSAPI响应中是否收到相同的错误消息。

在尝试为缺陷添加附件时,我在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 = >>>?<<< ]

值得注意的是404错误代码。此外,"无法解析输入流…"错误消息不是来自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'}

请注意"contentencoding":"gzip"。我怀疑请求模块(我在MacosPython2.6中使用0.13.3)正在对PUT请求进行gzip编码,但Rally API服务器没有正确解码。

最新更新