m0nhawk / grafana_api Goto Github PK
View Code? Open in Web Editor NEWYet another Python library for Grafana API
Home Page: https://m0nhawk.github.io/grafana_api/
License: MIT License
Yet another Python library for Grafana API
Home Page: https://m0nhawk.github.io/grafana_api/
License: MIT License
Describe the bug
Traceback when connecting to Grafana
Traceback (most recent call last):
File "generateGrafanaGraphs.py", line 245, in <module>
main(sys.argv)
File "generateGrafanaGraphs.py", line 241, in main
createGrafanaGRaphs(uplinks)
File "generateGrafanaGraphs.py", line 107, in createGrafanaGRaphs
protocol='http')
File "/usr/local/lib/python2.7/dist-packages/grafana_api/grafana_face.py", line 17, in __init__
self.teams = Teams(self.api)
File "/usr/local/lib/python2.7/dist-packages/grafana_api/api/team.py", line 6, in __init__
super().__init__(api)
TypeError: super() takes at least 1 argument (0 given)
To Reproduce
Steps to reproduce the behavior:
Fix
Use super(Teams,self)
class Teams(Base):
def __init__(self, api):
super(Teams,self).__init__(api)
self.api = api
Dear Andrew,
first things first: Thank you so much for conceiving and maintaining this library. We are using it in grafana-wtf, which you also might like.
Now, I just found @vinnyfuria reported about Grafana Dashboards being moved to the "General" folder when updating them within grafana-toolbox/grafana-wtf#5.
Have you also been able to observe this behavior? Maybe it is only happening with Grafana 7? Sorry that I am currently not able to verify this as I don't have access to any Grafana 7 instance yet. I know I could rig up a Docker container for that, but nevertheless I wanted to report this to you in the hope you will be quicker than me.
Thanks already for looking into this and with kind regards,
Andreas.
Is there any "timeout" option , when creating snapshot using HTTP API, not only via grafana GUI. Because when there are complex queries to execute on background, query is failing without timeout option.
Thanks in advance.
Describe the bug
pip install -U grafana_api
Collecting grafana_api
Downloading grafana_api-1.0.0.tar.gz (17 kB)
ERROR: Command errored out with exit status 1:
command: /home/vagrant/testenvironment/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-sszj54t9/grafana-api/setup.py'"'"'; file='"'"'/tmp/pip-install-sszj54t9/grafana-api/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-sszj54t9/grafana-api/pip-egg-info
cwd: /tmp/pip-install-sszj54t9/grafana-api/
Complete output (19 lines):
fatal: Not a git repository (or any of the parent directories): .git
Traceback (most recent call last):
File "/tmp/pip-install-sszj54t9/grafana-api/setup.py", line 8, in get_version
["git", "describe", "--tags", "--abbrev=0", "--match=[0-9]"]
File "/usr/lib64/python3.6/subprocess.py", line 356, in check_output
**kwargs).stdout
File "/usr/lib64/python3.6/subprocess.py", line 438, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['git', 'describe', '--tags', '--abbrev=0', '--match=[0-9]']' returned non-zero exit status 128.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-sszj54t9/grafana-api/setup.py", line 24, in <module>
version=get_version(),
File "/tmp/pip-install-sszj54t9/grafana-api/setup.py", line 13, in get_version
"The version number cannot be extracted from git tag in this source "
RuntimeError: The version number cannot be extracted from git tag in this source distribution; please either download the source from PyPI, or check out from GitHub and make sure that the git CLI is available.
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
To Reproduce
Steps to reproduce the behavior:
pip install -U grafana_api
Expected behavior
should have been installed
grafana_api
: [ 1.0.0]Describe the bug
dashboard.update_dashboard and folder.update_folder state that they will create a dashboard if it doesn't exist. If 'overwrite' is set to True though the actual Grafana API seem to return a 404 which is passed through the grafana_api library as a ClientError. It seems that
To Reproduce
Steps to reproduce the behavior:
Expected behavior
According to the documentation of the grafana_api, these function calls should create or update, so my expected outcome was that the single call would handle both. Or it should at least return the response as a 404 that I can handle without requiring an exception catch.
Versions
grafana_api
: [ 1.0.3 ]Additional context
Add any other context about the problem here.
Describe the bug
Currently, the add_annotation
method supports
time
timeEnd
isRegion
tags
text
parameters, while the current API lists
dashboardId
panelId
time
timeEnd
tags
text
allowing both global, region and annotations linked to a panel (which was what I'm after, btw).
Expected behavior
Support the full set of functions supported by Grafana.
Versions
grafana_api
: grafana-api==1.0.0edit - typos
What API call you use?
grafana_api.folder.update_folder(id, "title"):
What is the actual output?
Client Error 412: {"message":"The folder has been changed by someone else","status":"version-mismatch"}
What is the expected output?
The api should change the folder title and potentially ask for overwrite or folder version
(see: https://grafana.com/docs/http_api/folder/#update-folder)
Grafana API for "Find Annotation" details that the time range parameters are "from" and "to".
this module uses time range parameters "time_from" and "time_to" which are incorrect.
from Grafana example get annotation:
GET /api/annotations?from=1506676478816&to=1507281278816&tags=tag1&tags=tag2&limit=100
this module GET URI:
GET /api/annotations?time_from=1597179600&time_to=1597266000&limit=100
The problem is that if Grafana API doesn't get time range it finds ALL annotations (should have been none from my POV).
So it's easy to miss when testing the API as Grafana will response with annotation it finds but they are not related to the time range.
Describe the bug
I'd like to create annotations that contain 1..n tags but passing an array or tuple to the add_annotation method fails with an unmarshal error:
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
File "/Users/megamorf/.local/share/virtualenvs/webhooks-29Gd7Fk5/lib/python3.7/site-packages/grafana_api/api/annotations.py", line 88, in add_annotation
r = self.api.POST(annotations_path, json=payload)
File "/Users/megamorf/.local/share/virtualenvs/webhooks-29Gd7Fk5/lib/python3.7/site-packages/grafana_api/grafana_api.py", line 127, in __request_runnner
raise GrafanaBadInputError(response)
grafana_api.grafana_api.GrafanaBadInputError: Bad Input: `[{'classification': 'DeserializationError', 'message': 'json: cannot unmarshal array into Go struct field PostAnnotationsCmd.tags of type string'}]`
To Reproduce
Steps to reproduce the behavior:
from grafana_api.grafana_face import GrafanaFace
import time
tags = ['one','two','flex']
grafana_api = GrafanaFace(auth=api_token, host='localhost', port=3000)
grafana_api.annotations.add_annotation(
time_from=int(time.time()),
is_region=False,
tags=tags,
text="Job #345"
)
Expected behavior
Creating an annotation with multiple tags works when I do it without your code:
import requests
import json
import time
from datetime import datetime
example_annotation = {
"time": int(time.time()),
"tags": ["one", "two", "flex"],
"text": str(datetime.now()),
}
def add_annotation_raw(annotation):
resp = requests.post('http://localhost:3000/api/annotations',
json=annotation,
headers = {'Authorization': 'Bearer <api_key>'}
)
resp.raise_for_status()
print('Created annotation. ID: {}'.format(resp.json()["id"]))
>>> add_annotation_raw(example_annotation)
Created annotation. ID: 9
{'alertId': 0,
'alertName': '',
'avatarUrl': '',
'created': 1577398963875,
'dashboardId': 0,
'data': {},
'email': '',
'id': 9,
'login': '',
'newState': '',
'panelId': 0,
'prevState': '',
'tags': ['one', 'two', 'flex'],
'text': '2019-12-26 23:11:30.178468',
'time': 1577398290,
'timeEnd': 1577398290,
'updated': 1577398963875,
'userId': 0},
Versions
version=6.5.1 commit=1763a0f
0.9.2
Token
Creating a Dashboard with custom panels caused UI to be un responsive. I accidentally put incorrect gridPos
values which caused the web app to freeze when entering the dashboard.
To Reproduce
Edit the JSON to be like:
some_grid_pos = {"h": 3, "w": 4, "x": 0, "y": 0}
payload["gridPos"] = json.dumps(some_grid_pos)
grafanaclient.dashboard.update_dashboard(dashboard={'dashboard': dashboard})
I know what caused this to happen, it's the extra json.dumps() that added /
next to ""
in the JSON format but you guys should validate this somehow.
This seems like a major bug
Describe the bug
The Status of REST API realization
mentioned Dashboard & Folder permissions has been added, but I do not see any permissions-related code in grafana_api
api.
To Reproduce
N/A
Expected behavior
Code containing updating/removing permissions for Dashboard & Folders.
Versions
grafana_api
: v1.0.1Additional context
It would be beneficial if you include examples on how to update permissions for Dashboard & Folder.
Dear Andrew,
I just added a monkey-patch workaround to grafana-wtf
, minted from the patch contributed on behalf of #85 and fixing issue #82, see also grafana-toolbox/grafana-wtf@b77f90b.
May I humbly ask if you believe you will be able to come back to maintaining this package? Otherwise, while I am also constrained on resources, I would like to offer to take this over for the benefit of the community.
With kind regards,
Andreas.
Describe the bug
The requests never timeout, this is not a good idea in general
Expected behavior
The user should be able to set one and there should be a default (maybe 10s)
Describe the bug
Authentication by api token is not working
To Reproduce
grafana_api = GrafanaFace(auth='abcdefg', host='grafana.XXX.com')
grafana_api.folder.get_all_folders()... just any kind of API call
RESULT below,
grafana_api.grafana_api.GrafanaUnauthorizedError: Unauthorized
Expected behavior
I thought that since these kinds of call is not about admin API api token based authentication must work. So I created API key, which is not expired, and gave the role admin. But it is still not working. Also, our organization uses google OAuth for authentication. So using basic auth is not applicable here.
Versions
grafana_api
: [ 1.0.3 ]Additional context
Add any other context about the problem here.
Describe the bug
Using update_dashboard method fails.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The dashboard is created.
Versions
grafana_api
: [/dashboards/db ]Additional context
My code. Works with normal requests library.
import grafana_api
import requests
with open("test.json") as json_data:
# Using template from: https://grafana.com/docs/grafana/latest/http_api/dashboard/#create-update-dashboard
test = json_data.read()
# Fails.
api = grafana_api.GrafanaFace(auth="my token", host="some grafana host")
# This method works so authentication is fine.
print(api.dashboard.get_home_dashboard())
print(api.dashboard.update_dashboard(test))
# Works all good with requests.
resp = requests.post("https://grafanahost.com/api/dashboards/db", headers={"Accept": "application/json", "Content-Type": "application/json", "Authorization": "Bearer token here"}, data=test)
print(resp.status_code)
print(resp.text)
print(resp.json())
Full traceback:
Traceback (most recent call last):
File ".\test.py", line 12, in <module>
print(api.dashboard.update_dashboard(str(test)))
File "C:\Users\\.virtualenvs\lib\site-packages\grafana_api\api\dashboard.py", line 26, in update_dashboard
r = self.api.POST(put_dashboard_path, json=dashboard)
File "C:\Users\.virtualenvs\\lib\site-packages\grafana_api\grafana_api.py", line 111, in __request_runnner
return r.json()
File "C:\Users\\lib\site-packages\requests\models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "c:\python37\Lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "c:\python37\Lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "c:\python37\Lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Hello! Thanks for grafana_api!
I try create user.
from grafana_api.grafana_face import GrafanaFace
grafana_api = GrafanaFace(auth=('admin', 'admin'), host='localhost', port=3000)
user = grafana_api.admin.create_user('User')
error:
grafana_api.grafana_api.GrafanaBadInputError: Bad Input: `[{'classification': 'DeserializationError', 'message': 'json: cannot unmarshal string into Go value of type dtos.AdminCreateUserForm'}, {'fieldNames': ['Password'], 'classification': 'RequiredError', 'message': 'Required'}]`
Try json
user = grafana_api.admin.create_user('{"name":"User","password":"password"}')
same error
Hey,
I think one missing method that should be there for sure is
test_connection()
something that tells you that the connection info you inserted in GrafanaFacade constructor are valid
Thanks in advance
Describe the bug
Method update_folder of folder class raises TypeError('not all arguments converted during string formatting')
To Reproduce
Steps to reproduce the behavior:
g = GrafanaFace(...)
TypeError('not all arguments converted during string formatting')
Expected behavior
Method update_folder working as expected
Versions
grafana_api
: >= 0.7.3Describe the bug
All the references to Organization are called Organisation in the code, this is not correct.
To Reproduce
Steps to reproduce the behavior:
grafana = grafana_api.GrafanaFace(
host=GRAFANA_HOST,
auth=GRAFANA_KEY,
protocol="https",
port=443
)
log.debug(grafana.organization)
Expected behavior
Organization API should be returned instead of None
Versions
grafana_api
: [ grafana-api==0.5.2 ]pypi.org has various releases which do not have the appropriate tag in the git repo. Please push your tags!
What Grafana API endpoint the library is missing?
Support for creating, updating and removing notifications channels (see this page).
Describe the bug
Hello. When I try to update a dashboard which contains more than 40 plots using the following code:
grafana_api.dashboard.update_dashboard(dashboard={'dashboard': dashboard_json['dashboard'], 'folderid': dashboard_json['meta']['folderId'], 'overwrite': True})
I have the following issue:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
chunked=chunked,
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 392, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1252, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1298, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1247, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1065, in _send_output
self.send(chunk)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 987, in send
self.sock.sendall(data)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1034, in sendall
v = self.send(byte_view[count:])
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1003, in send
return self._sslobj.write(data)
socket.timeout: The write operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 725, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 403, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/local/lib/python3.7/site-packages/urllib3/packages/six.py", line 734, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
chunked=chunked,
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 392, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1252, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1298, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1247, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1065, in _send_output
self.send(chunk)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 987, in send
self.sock.sendall(data)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1034, in sendall
v = self.send(byte_view[count:])
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1003, in send
return self._sslobj.write(data)
urllib3.exceptions.ProtocolError: ('Connection aborted.', timeout('The write operation timed out'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', timeout('The write operation timed out'))
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I would like to get an updated dashboard.
Versions
Additional context
What API call you use?
users.find_user(...)
What is the actual output?
Client error 403 permission denied.
What is the expected output?
it should be showing user.
This https://github.com/m0nhawk/grafana_api/blob/master/grafana_api/grafana_api.py#L101 should say server
instead of client
.
hi, i can't get how to use this api. The return of any call is only a link ?
What Grafana API endpoint the library is missing?
Describe and link the Grafana API endpoint which are currently missing.
I have an old dashboard, it can be treat as a template dashboard, and now I want to create some dashboard base on it, I only need to modify some query parameters on the new dashboard, can you give me some help? thanks!!!
Describe the bug
Hi, trying to find the documentation. The link in github homepage points to https://m0nhawk.github.io/grafana_api/ same in the documentation site. Would be great if it could be updated in github page, so its easy to find documentation
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Link points to page without 404
Thanks
Describe the bug
folder.create_folder() doesn't create folders. It only returns the list of existing folders.
To Reproduce
Steps to reproduce the behavior:
secret = "YOUR_SECRET_HERE"
url = "YOUR_URL_HERE"
from grafana_api.grafana_face import GrafanaFace as GF
gf = GF(auth=secret, host=url)
res = gf.folder.create_folder('NEW_TITLE')
# `res` contains only existing folders, no new folder is created
Expected behavior
Expected new folder is created.
Versions
v7.0.3 (00ee734baf)
grafana_api
: 1.0.2
GrafanaServerError
and GrafanaClientError
should inherit from GrafanaException
instead of Exception
.
Is there a possibilty you could add the following code to the next release please?
def get_dashboard_by_name(self, dashboard_name):
"""
:param dashboard_name:
:return:
"""
get_dashboard_path = "/dashboards/db/%s" % dashboard_name
r = self.api.GET(get_dashboard_path)
return r
Firstly, thanks for a very useful package! The new refactoring of the module structure also looks like a good step forward.
However, the module bundled in the latest package (v0.3.1) cannot actually be imported:
>>> import grafana_api
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/grafana_api-0.3.1-py3.6.egg/grafana_api/__init__.py", line 1, in <module>
from .grafana_face import GrafanaFace
File "/usr/local/lib/python3.6/site-packages/grafana_api-0.3.1-py3.6.egg/grafana_api/grafana_face.py", line 2, in <module>
from .api import Base
ModuleNotFoundError: No module named 'grafana_api.api'
The grafana_api.api
submodule needs to be explicitly included in setup.py
in order for it to be included in the package. I've gone ahead and created a PR which I believe addressed this: #4.
First of all I am really thankful for your efforts to create this very useful library.
Now, I am having trouble with create_new_snapshot
api, as when I use it, instead of static data, dashboard is keep on showing new data. Now interesting thing is, this is only happening if I am exporting it to snapshot.raintank.io, if I take local snapshot, it works fine.
Here is the code I used:
ref = grafana_api.search.search_dashboards()
for r in ref:
print(r)
dashboard1 = grafana_api.dashboard.get_dashboard(r['uid'])
if r['uid'] == 'gatling':
res = grafana_api.snapshots.create_new_snapshot(name="run_id_24"+r['title'], dashboard=dashboard1['dashboard'], external=True, key="abcd")
print(res)
break
Versions
grafana_api
: [ 1.0.3]So can you guys help me with it.
Here I am attaching one of the snapshot link.
Hello! Thanks for grafana_api.
How correct create organization ?
grafana_api.organization.create_organization("name")
Output
Traceback (most recent call last):
File "/home/user/russianpost/service/python-tools-adapter/Grafana/manage-grafana-by-api.py", line 90, in <module>
grafana_api.organization.create_organization("name")
File "/usr/local/lib/python3.6/dist-packages/grafana_api/api/organization.py", line 35, in create_organization
r = self.api.POST(create_orgs_path, json={"name": organization["name"]})
TypeError: string indices must be integers
Process finished with exit code 1
Describe the bug
in grafana_api.py, line 114:
except Exception as error:
print('Caught this error: ' + repr(error))
you are catching all exceptions you were throwing before - with the result, that all issues are hidden to the code that actually uses grafana_api. This is pretty much broken.
According to the commit, this is supposed to fix unit tests. If this fixes unit tests, they are also broken...
Expected would be that the errors are being raised.
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1741, in
main()
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1735, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1135, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/ali/Dropbox/WORK/Workspace/grafana-dash/list-dash.py", line 6, in
grafana_api.search.search_dashboards(dashboard_ids=9)
File "/Users/ali/Dropbox/WORK/Workspace/venv/lib/python3.7/site-packages/grafana_api/api/search.py", line 57, in search_dashboards
r = self.api.GET(list_dashboard_path)
File "/Users/ali/Dropbox/WORK/Workspace/venv/lib/python3.7/site-packages/grafana_api/grafana_api.py", line 99, in __request_runnner
"Client Error {0}: {1}".format(r.status_code, r.json()['message'])
File "/Users/ali/Dropbox/WORK/Workspace/venv/lib/python3.7/site-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/init.py", line 348, in loads
return _default_decoder.decode(s)
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Describe the bug
Hi ,
I have installed the pip install grafana_api, my aim is to retrieve the data from a particular datasource.
I did this
Step 1 : pip3 install grafana_api
Step 2: grafana_api = GrafanaFace(auth=api_key,host='https://XXX/api/datasources')
OR
grafana_api = GrafanaFace(auth=('user_name', pwd), host='https://XXX/api/datasources')
Step 3: Commands works fine but when i do this
grafana_api.datasource.get_datasource_by_id("14")
or grafana_api.datasource.get_datasource_by_id(14)
it fails with below error
**
requests.exceptions.ConnectionError: HTTPConnectionPool(host='https', port=80): Max retries exceeded with url: //XXX/api/datasources/api/datasources/14 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10b2ece50>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))
**
Same works when i'm using request.get on same creds. i.e user name and pwd.
Do, let me know if anything else needed
Thanks
Suprabhat
Additional context
Add any other context about the problem here.
What API call you use?
Provide a small example to reproduce the bug.
grafana_api = GrafanaFace(auth=(config["grafana_user"],config["grafana_pass"]),host=config["grafana_url"])
print(grafana_api.organizations.list_organization())
print(grafana_api.organization.get_current_organization())
grafana_api.organizations.switch_organization(organization_id=15)
The first two queries work fine, the last one returns a JSON error.
What is the actual output?
Copy or describe the actual result.
Traceback (most recent call last):
File "provision_api.py", line 19, in
grafana_api.organizations.switch_organization(organization_id=15)
File "/home/yentel/.local/lib/python3.7/site-packages/grafana_api/api/organization.py", line 132, in switch_organization
r = self.api.POST(switch_user_organization)
File "/home/yentel/.local/lib/python3.7/site-packages/grafana_api/grafana_api.py", line 136, in __request_runnner
return r.json()
File "/usr/lib/python3/dist-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3/dist-packages/simplejson/init.py", line 518, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
obj, end = self.raw_decode(s)
File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
What is the expected output?
Something without an error that tells me I've switched to organization with id 15? :-)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.