Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
converting json into ?
#1
I am not a developer, just the guy that is blocked on a project because of this.
I was given an app that is supposed to create a json list. It is then meant to be hit by a url that will create a drop down in Rundeck that fills out build number options from Jenkins. Originally i could not get it to work without throwing a TypeError: the JSON object must be str, not 'bytes' error.  I can get it working in a browser by doing: 

def parseJenkinsJSON(json_text):
    str_response = json_text.readall().decode('utf-8')
    json_data = json.loads(str_response)
but now rundeck will throw Exception: java.lang.Exception: Unexpected content type received: text/html; charset=utf-8. 

How would I convert the json into something that is readable by Rundeck? Per rundeck: Three styles of return data are supported: simple list, simple object, and a name/value list. I need it to be a name/value list, which it is.

Here is an example of the returned json: 
[{"name":" rms-9.06.3_390 #67","value":"http://myurl.com/job/rms-9.06.3_390/67/artifact/application-web/build/libs/rms.war"}]

The whole app is only 70 ish lines, so if it would be more help to see the whole thing I can upload it somewhere.
Reply
#2
(Aug-16-2017, 07:40 PM)cmietzner Wrote: Unexpected content type received: text/html; charset=utf-8

To me, that looks like your content is right, but you're sending the wrong http header.  How you change that depends entirely on what framework you're using to send the http response.

For reference: https://developer.mozilla.org/en-US/docs...ntent-Type
Instead of text/html, you want to be sending application/json, so the whole http header would be Content-Type: application/json; charset=utf-8.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020