Problem with json_query.

Posted on
Sat Jun 06, 2020 5:45 am
eriass offline
Posts: 26
Joined: May 12, 2016

Problem with json_query.

I have a problem with a json_query that im getting crazy at...

my query is:

json_query = '{ "accessToken": "' + current_access_token + '", "refreshToken": "' "test=" '"}'

When I look at whats sending I see this:
{ "accessToken":
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBY2NvdW50SWQiOjExNDcyLCJVc2VySWQiOjEwMTg4LCJ1bmlxdWVfbmFtZSI6IjExNDcyIiwicm9sZSI6IlVzZXIiLCJuYmYiOjE1OTE0NDE1MTUsImV4cCI6MTU5MTUyNzkxNSwiaWF0IjoxNTkxNDQxNTE1fQ.ENaf4DkiKlzakALAWd8ImLYQH1QScK7pD2se7zmP_TU", "refreshToken": "test: "}

The problem is the character = that is after test, it automaticly changes to : in my query,....

I have a variable that is called current_refresh_token that I use otherwise, but the refresh_token always has = at the end, and it automaticly changes it to : every time. I dont get why.. At the example above I have replaced it with just test=

Posted on
Sat Jun 06, 2020 8:16 am
FlyingDiver offline
User avatar
Posts: 7257
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Problem with json_query.

Can you repost all that using CODE tags so we can be sure we're seeing the code you're actually sending?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Jun 06, 2020 10:40 am
eriass offline
Posts: 26
Joined: May 12, 2016

Re: Problem with json_query.

import urllib2, json

current_refresh_token = indigo.variables[852267179].value
current_access_token = indigo.variables[1083868490].value

url = 'https://postb.in/1591445751895-9908084962517'

json_query = '{ "accessToken": "' + current_access_token + '", "refreshToken": "' "test=" '"}'

request = urllib2.Request(url, data=json_query)

request.add_header('accept', 'application/json')

response = urllib2.urlopen(request)

responseString = response.read()
responsecode = response.getcode()
responseJson = json.loads(responseString)

indigo.server.log(str(responseJson))
Last edited by eriass on Sat Jun 06, 2020 10:42 am, edited 1 time in total.

Posted on
Sat Jun 06, 2020 10:42 am
eriass offline
Posts: 26
Joined: May 12, 2016

Re: Problem with json_query.

current_refresh_token isnt in use as I wrote before, I replaced it with the text "test="

Posted on
Sat Jun 06, 2020 10:52 am
FlyingDiver offline
User avatar
Posts: 7257
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Problem with json_query.

First, what you were constructing wasn't valid JSON. Second, use requests instead of urllib2, it's much easier.

https://requests.readthedocs.io/en/master/

Something like this:

Code: Select all
import requests
import json

current_refresh_token = indigo.variables[852267179].value
current_access_token = indigo.variables[1083868490].value

url = 'https://postb.in/1591445751895-9908084962517'

json_data = '{ "accessToken":  current_access_token, "refreshToken":  current_refresh_token}'

request  = requests.get(url, json= json_data)

indigo.server.log(request.text)

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Jun 06, 2020 12:23 pm
eriass offline
Posts: 26
Joined: May 12, 2016

Re: Problem with json_query.

Thanks!
But when I run that I get this in the log:

"500 - Internal Server Error"


Any clue?

Here is the code:


Code: Select all
import requests
import json

current_refresh_token = indigo.variables[852267179].value
current_access_token = indigo.variables[1083868490].value

url = 'https://postb.in/1591466744873-5514116082340'

json_data = '{ "accessToken":  current_access_token, "refreshToken":  current_refresh_token}'

request  = requests.get(url, json= json_data)

indigo.server.log(request.text)

Posted on
Sat Jun 06, 2020 12:39 pm
FlyingDiver offline
User avatar
Posts: 7257
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Problem with json_query.

Please learn to use the "Code" tags.

My bad, I didn't set that up correctly. You called the parameters JSON, but they're not really. I think this should work:

Code: Select all
import requests

current_refresh_token = indigo.variables[852267179].value
current_access_token = indigo.variables[1083868490].value

url = 'https://postb.in/1591466744873-5514116082340'

payload = {"accessToken": current_access_token, "refreshToken": current_refresh_token}
request = requests.get(url, params = payload)

indigo.server.log(request.text)

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Jun 06, 2020 1:09 pm
jay (support) offline
Site Admin
User avatar
Posts: 18255
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Problem with json_query.

FlyingDiver wrote:
Please learn to use the "Code" tags.


I edited your last post @eriass to illustrate how code tags work such that script code is formatted in a readable format.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jun 07, 2020 2:30 pm
eriass offline
Posts: 26
Joined: May 12, 2016

Re: Problem with json_query.

Thanks!!!! :D

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest