httpGet returning unicode html

Morning humans

I have manged to put together an api call that appears to work in that it returns a thing.
But the returned object is in unicode/ html, very dense, and I can’t begin to work out how to slice and dice it to extract useful things.
I have a project script:

import java.lang
from import URLEncoder
import logging

class JythonClient:
	def Coruson_api(self, userName, passWord):
		baseUrl = ''
		self.client = = userName, password = passWord)
		headers = {"tenant":""}
	def get_reports(self, coruson_request, userName, passWord):
		baseUrl = ''
		base = ''
		encode_request =, 'UTF-8')
		url = base+encode_request
		headers = {"tenant":""}

		response = = url, username = userName, password = passWord, headerValues = headers)
		return response

and a component script on a button, that gets the required username and password, and the request dictionary info:

def runAction(self, event):
	This event is fired when the 'action' of the component occurs.

		self: A reference to the component that is invoking this function.
		event: An empty event object.
	userName = (textField).props.text
	passWord = (password field).props.text
	reports = apiReports.JythonClient().system_api(userName, passWord)
	formName = "FormName"
	owner = (dropdown).props.options[(dropdown).props.value]['label']
	startDate = (component).props.value
	endDate = (component).props.value
	coruson_request = {"FormName":formName, "StartDate":startDate, "EndDate":endDate, "Owner":owner}
	response = apiReports.JythonClient().get_reports(coruson_request, userName, passWord)
	self.custom.response = response

Is there something I need to add/remove in order to get this as json and/or convert it, and/or make it readable as a table or other component?

I’m trying to bind the response to a table at the moment, but it just gets upset about having a string instead of an array.

There are a few things I find weird about the code you’ve shown:

  • You’re calling apiReports.JythonClient().system_api(userName, passWord) But there’s no method named system_api in the class definition. I suspect you swapped Coruson_api for system_api in the second code snippet.
  • encode_request =, 'UTF-8') looks weird. I’m not sure it does what you think it does.
    After trying what that function does, I think it converts a string to an url formatted string. But it doesn’t convert a dict into url parameters… So you’re formatting a dict into a url compatible string. Which is probably not what you want to do
    EDIT: I don’t think this is very clear… Let me rephrase: You’re converting a dict into a string, and then replacing characters that aren’t allowed in a url by codes that correspond to those characters, without converting it into url parameters before. Basically, it converts the dict’s brackets and dots into character codes.
    dicts look like {'foo': "FOO", 'bar': 42}
    url parameters look like foo=FOO&bar=42
    urllib.urlencode() can convert a dict to url parameters for you.
  • the doc for the api is a mess and I couldn’t find how to specify a return format, but maybe there’s a parameter you can add to get a json response
  • do you NEED classes for this ? What good is the Coruson_api (or system_api) method here ? What is it supposed to do ? You’re passing everything to get_reports anyway.
  • you’re importing from import URLEncoder, then calling

Lastly, what does the returned string look like ? It might help determine if it’s a proper response.

  • I did! I was trying to do the ‘make code generic’ thing for posting it here, then I got distracted. They match irl.
  • I think urllib has started having compatibility issues? I’ve been replacing it with the instead, which has worked elsewhere (when urllib.urlencode was throwing errors).
    I did think putting the string part first might do something weird, but it didn’t seem to be happy with the dictionary. It might want different syntax?
    *I probably don’t need the class, no. But it was in the code I nicked off the forums, so I kept it…
    *Yeah. The info I found about urllib getting wonky and using encoder instead had it set out that way, so I haven’t faffed with it. It’s working happily in another project, so I didn’t fix a not-apparently-broken thing…

Thank you for the comprehensive response!
Do you know what the syntax ought to be for feeding a dictionary to

According to its javadoc, that’s not what it’s for. What it does is

Translates a string into application/x-www-form-urlencoded format using a specific encoding scheme. This method uses the supplied encoding scheme to obtain the bytes for unsafe characters.

You need to format your dict into a query string first. If you don’t want to use urllib.urlencode (it should be safe to use), maybe java has a function for this, but I don’t know much about java.
Otherwise, you can do it yourself, with something like this:

def format_params(params):
	if params:
		return "?" + "&".join("{}={}".format(key, value) for key, value in params.items())
		return ""

Then you can feed that string to java’s URLEncoder.urlencode()

1 Like

I got it working :smiley:
running the base url and dictionary through httpClient did the encoding, then using the output of that as the url in httpGet got me a good response.
putting “format”:“json” as part of the dictionary forced that.
Now I just have to get rid of a bit of superfluous info the table won’t parse, and we might be set…

Thank you again

I would really, really strongly encourage you to migrate to, which takes care of basically all of the encoding and decoding for you when dealing with a typical REST API: