Code Monkey home page Code Monkey logo

Comments (3)

Yentel avatar Yentel commented on July 20, 2024

FYI: I've been testing different servers.
It works on my personal grafana instance but not on the one we use at work.
So far, after setting server settings to the exact same values, this does not work on my work instance.

The only difference so far is that the one on my work is using version "Grafana v7.1.3 (5723d951af)"

Deleting a datasource also seems to work... which is also a post request... I'm out of options here

from grafana_api.

m0nhawk avatar m0nhawk commented on July 20, 2024

It should either output the 200 response with:

{"message":"Active organization changed"}

Or some other message, I was not able to reproduce it with multiple Grafana versions.


From the error, it's successfully switches the organization (or at least returning status code less than 400) and returns non-JSON response:

File "/home/yentel/.local/lib/python3.7/site-packages/grafana_api/grafana_api.py", line 136, in __request_runnner
return r.json()

I'd recommend to test cURL to see what's going on (see below), unfortunately, right now the library doesn't have nice debug capabilities (though, I have this in mind).

As for cURL, you can run the following command and see what's going on:

curl -X POST -u myusername:mypassword http://somesite.com:port/api/user/using/15

from grafana_api.

Yentel avatar Yentel commented on July 20, 2024

Sorry for the late reply, some other project got prio above this provisioning grafana side project.

curl -X POST -u admin:somethingsecret https://dashboard.myorg.com/api/user/using/7
{"message":"Active organization changed}

However, if I run my script, I get the same error as above :-(
Code:

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=1)

The first two prints work fine, thus, authentication seems to work.
However, the last part, switching orgs, fails with this error:

Traceback (most recent call last):
  File "provision_api.py", line 18, in <module>
    grafana_api.organizations.switch_organization(organization_id=1)
  File "/usr/local/lib/python3.7/site-packages/grafana_api/api/organization.py", line 132, in switch_organization
    r = self.api.POST(switch_user_organization)
  File "/usr/local/lib/python3.7/site-packages/grafana_api/grafana_api.py", line 136, in __request_runnner
    return r.json()
  File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 898, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/Cellar/python/3.7.7/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.7/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.7/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)
python3 --version
Python 3.7.7
pip3 install grafana_api
Requirement already satisfied: grafana_api in /usr/local/lib/python3.7/site-packages (1.0.3)
Requirement already satisfied: requests>=2.23.0 in /usr/local/lib/python3.7/site-packages (from grafana_api) (2.24.0)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/site-packages (from requests>=2.23.0->grafana_api) (1.25.8)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/site-packages (from requests>=2.23.0->grafana_api) (2.8)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/site-packages (from requests>=2.23.0->grafana_api) (2019.11.28)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/site-packages (from requests>=2.23.0->grafana_api) (3.0.4)

from grafana_api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.