One option you can use is the Python query runner, which will let you reformat this data as needed. Or, if you find yourself working with data from this source very often, you could write a custom query runner to do it.
Hereâs the python query I used to make it work:
import requests
url = "https://erddap.osupytheas.fr/erddap/tabledap/meteo_toulon_2ce5.json?time,Temperature&time>=2022-06-25T00%3A00%3A00Z&time<2022-06-27T00%3A00%3A00Z&.draw=linesAndMarkers&.marker=3|5&.color=0x000000&.colorBar=|||||&.bgColor=0xffccccff"
data = requests.get(url).json()
result["columns"] = [{"name": name, "type":"string"} for name in data["table"]["columnNames"]]
for row in data["table"]["rows"]:
this_row = {}
for colname, value in zip(data["table"]["columnNames"], row):
this_row = {**this_row, **{colname: value}}
result["rows"].append(this_row)
I have found what seems to be the solution of the error above⌠It is that we have to include also
REDASH_ADDITIONAL_QUERY_RUNNERS=redash.query_runner.python
in the /opt/redash/env file
So now, the python script can run, but with a new syntax error
Error running query: <type âexceptions.SyntaxErrorâ> invalid syntax (, line 12)
line12 is: this_row = {**this_row, **{colname: value}}
do you know where the error comes from? since I have textually copied the code you gave me
In a first step I would want to make your code work, before understanding how it works
thanks for your help
What version of Redash do you use? My example assumes you are on Redash V10, which uses Python 3. The syntax error could be because you are on an older version of Redash that uses Python 2.
If thatâs the case you can change the code to:
# python2 version
import requests
url = "https://erddap.osupytheas.fr/erddap/tabledap/meteo_toulon_2ce5.json?time,Temperature&time>=2022-06-25T00%3A00%3A00Z&time<2022-06-27T00%3A00%3A00Z&.draw=linesAndMarkers&.marker=3|5&.color=0x000000&.colorBar=|||||&.bgColor=0xffccccff"
data = requests.get(url).json()
result["columns"] = [{"name": name, "type":"string"} for name in data["table"]["columnNames"]]
for row in data["table"]["rows"]:
this_row = {}
for colname, value in zip(data["table"]["columnNames"], row):
this_row = this_row.update({colname: value})
result["rows"].append(this_row)
I dont know why the this_row.update({colname: value}) doesnât work in redash?
since I tested the same successfully in a python2 and python3 console
Error running query: <type âexceptions.AttributeErrorâ> âNoneTypeâ object has no attribute âupdateâ
So I replaced the .update function, by something equivalent this_row[colname]=value
and it seems to workâŚ
I get now my 2 columns âtimeâ and âTemperatureâ and I can graph temperature over time from an erddap json flow
for row in data[âtableâ][ârowsâ]:
this_row = {}
for colname, value in zip(data[âtableâ][âcolumnNamesâ], row): #this_row = this_row.update({colname: value})
this_row[colname]=value
result[ârowsâ].append(this_row)
In conclusion, if you can tell me how and where to get the redash v10 version? because I think I use the v8 from GitHub - getredash/setup: Setup scripts for Redash Cloud Images
other question, how can I know the python version which run into the docker redash contianer?
You could also just follow the instructions to upgrade your V8 instance to V10: Upgrade from V8 to V10 Walkthrough - YouTube. Upgrading your V8 instance only takes a few minutes, especially if you used the setup script.
Note that the setup script has not been updated for V10 (yet). So the Docker instructions, or the upgrade path are the only way to install V10 without manually modifying the setup script.