Closed jsalatiel closed 3 years ago
I don't have a 9.5.5 version so I quickly spawned a Docker container using this image (gist for deployment). It worked as expected so I don't think this is a problem with GLPI version:
In [21]: with glpi_api.connect(url="http://127.0.0.1:8000/apirest.php/", apptoken="rclnhVer9lBzvdCA3HhXakMlXvXR4jfn4lrx84wz", auth="1EtQeajKpEZ6MbVkO15AEwg4iqVoO0CFtFh6H7ER", verify_certs=False) as glpi:
...: print(glpi.get_config()["cfg_glpi"]["version"])
...:
9.5.5
From your screenshots, everything looks good (API is activated, a client is authorized and activated, APP token generated, the user API token
is used) so I don't see where the problem is ...
Can you try this curl
command (adapt it with your URL and tokens):
curl -X GET -H "Content-Type: application/json" -H "App-Token: rclnhVer9lBzvdCA3HhXakMlXvXR4jfn4lrx84wz" -H "Authorization: user_token 1EtQeajKpEZ6MbVkO15AEwg4iqVoO0CFtFh6H7ER" http://127.0.0.1:8000/apirest.php/initSession
If it doesn't return a session_token
in JSON, you have bad tokens/configuration somewhere or there may be a bug in GLPI for your environment.
You can also try to activate low-level logs from the Python HTTP client for debugging to see what is really sent:
import http.client
http.client.HTTPConnection.debuglevel = 1
with glpi_api.connect(...
The curl command also returns the ERROR_LOGIN_PARAMETERS_MISSING. I will try to debug a bit more. Just one question, the user_token is the api_token from the profile page right?
There are personal token and api token on that page. So I suppose it is the api token.
I confirm this is the api token from the profile page that must be used (with the app token from API client).
I was curious so I take a quick look at GLPI issues, this one may be relevant to your problem.
The curl command works if I add the user_token=TOKEN_HERE as query parameter. Would it be possible to change your python api connector to send that as a query parameter instead of a header ?
I have just pushed a commit in the issue5 branch for that. I have done quick tests and it seems OK but, before I merge and tag, can you confirm it works well for you?
No, still not working. This is my full test file:
import glpi_api
import json
URL = 'https://glpi.mydomain/apirest.php/'
USERTOKEN= '$USERTOKEN_HERE'
APPTOKEN = '$APPTOKEN_HERE'
with glpi_api.connect(URL, APPTOKEN, auth=USERTOKEN ,verify_certs=False) as glpi:
print(glpi.get_config())
It still returns: glpi_api.GLPIError: (ERROR_LOGIN_PARAMETERS_MISSING)
Running curl -X GET -H "Content-Type: application/json" -H "App-Token: $APP_TOKEN" 'https://glpi.mydomain/apirest.php/initSession?user_token=$USERTOKEN'
returns {"session_token":"$some_token_here"}
# md5sum glpi_api.py
bcf03baa2ac9d591ce6ecafe7abe6d1f glpi_api.py
Sorry, forgot to said that you need to unset an argument (this was said in the doc which is not yet generated ...).
The default will still be to use headers, but you can change the behaviour by unsetting use_headers
argument:
with glpi_api.connect(URL, APPTOKEN, auth=USERTOKEN ,verify_certs=False, use_headers=False) as glpi:
print(glpi.get_config())
It worked ! Thanks!
Hello, Is this project still working on GLPI 9.5.5 ? I just tried a very simple use case, where:
app_token is taken from Application Token (app_token)![image](https://user-images.githubusercontent.com/5522389/119518944-5faa6280-bd4f-11eb-8d53-03fe4965b702.png)
and usertoken is the api_token inside user profile page. ( don't worry, tokens regenerated )![image](https://user-images.githubusercontent.com/5522389/119519128-8cf71080-bd4f-11eb-8c99-b2a7e32f6340.png)
But when I try to run the basic python script below it fails with the following log: glpi_api.GLPIError: (ERROR_LOGIN_PARAMETERS_MISSING)
Any ideas here ?
Api is enabled