← Back to team overview

python-jenkins-developers team mailing list archive

[Bug 1014733] [NEW] JSON queue info characters \r\n can cause ValueError

 

Public bug reported:

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']

** Affects: python-jenkins
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Python
Jenkins Developers, which is subscribed to Python Jenkins.
https://bugs.launchpad.net/bugs/1014733

Title:
  JSON queue info characters \r\n can cause ValueError

Status in Python API for Jenkins:
  New

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 manage notifications about this bug go to:
https://bugs.launchpad.net/python-jenkins/+bug/1014733/+subscriptions


Follow ups

References