JSON queue info characters \r\n can cause ValueError

Bug #1014733 reported by smarmit
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python Jenkins
New
Undecided
Unassigned

Bug Description

Hello.

In some cases a call to get_queue_info() has caused a ValueError exception. This looks to be caused by the case where the Jenkins server that's been queried returns JSON literal with carriage return \r and newline \n. Here's the relevant part of the exception:

----------------
File "/opt/python2.7/lib/python2.7/site-packages/jenkins/__init__.py", line 185, in get_queue_info
    return json.loads(self.jenkins_open(urllib2.Request(self.server + Q_INFO)))['items']
  File "/opt/python2.7/lib/python2.7/json/__init__.py", line 310, in loads
    return _default_decoder.decode(s)
  File "/opt/python2.7/lib/python2.7/json/decoder.py", line 346, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/python2.7/lib/python2.7/json/decoder.py", line 362, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Invalid control character at: line 1 column 633 (char 633)
----------------

I've been able to get my specific error by changing this line in def get_queue_info(self):

    return json.loads(self.jenkins_open(urllib2.Request(self.server + Q_INFO)))['items']

with these two lines:

    queue = self.jenkins_open(urllib2.Request(self.server + Q_INFO))
    return json.loads(queue.replace('\r\n', ''))['items']

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.