Rocket.chat: Fail to login with the REST API

Created on 10 Jul 2018  Â·  13Comments  Â·  Source: RocketChat/Rocket.Chat

I used the REST API to login, but the following error happened. I used wireshark to observe and although 200 is returned, not the json data, one html data is returned. I don't understand where the problem is.

File "D:/06_PythonProject/Test/RocketChat.py", line 19, in
main()
File "D:/06_PythonProject/Test/RocketChat.py", line 12, in main
rocket = RocketChat('XXXX', 'XXXXX', server_url='https://open.rocket.chat/home')
File "C:\Python27libsite-packages\rocketchat_API\rocketchat.py", line 21, in __init__
self.login(user, password)
File "C:\Python27libsite-packages\rocketchat_API\rocketchat.py", line 78, in login
if login_request.json().get('status') == "success":
File "C:\Python27libsite-packages\requests\models.py", line 896, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Python27lib\json__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "C:\Python27lib\json\decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python27lib\json\decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Most helpful comment

Had the same problems a couple of days ago. You can‘t use any LDAP based user when using the API. You have two choices imho:

  • set login fallback to true (see also #7642)
  • register and use an additional local Rocket.Chat user for the API

See also #4961 for further work on this issue.

All 13 comments

Above question is solved. The detail is that I used the wrong URL.
The correct URL is https://open.rocket.chat.

But I still have another question. Do I have to use login API via Https?
Because when I use login API to login to my rocket.chat server, 401 is return.
The URL is http://xxxxxx.

There is no restriction to HTTPS on login via REST API. If you are getting a response body like this:

{
    "status": "error",
    "error": "Unauthorized",
    "message": "Unauthorized"
}

It's a problem with your credentials.

Thank you for answering my question.
I have no ideas about credentials. Could you teach me how to solve it? Is it related with some settings?

In order to login you must have userId, x-auth-token passed in with your
headers

On Monday, July 16, 2018, WgxPlayup notifications@github.com wrote:

Thank you for answering my question.
I have no ideas about credentials. Could you teach me how to solve it? Is
it related with some settings?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/RocketChat/Rocket.Chat/issues/11411#issuecomment-405134964,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AH1ikq1fsNt2C_6voFwRHMcwbHOer2Qoks5uG_LigaJpZM4VIwzu
.

The REST API login only has two parameters: username and password. I think the user ID and x-auth-token are returned by the server.
If I used the LDAP to login to the server, is it the reason that I received 401?

Yes, i think you are right, it does not require authentication. I was
referring the old API docs.
Anyways are you sure u did register a user before passing in username and
password
The user you want to login with should have to be registered on the server,
and then use its credentials to pass in to the API call.

Can you tell me exactly, where are you facing the problem?

On Mon, Jul 16, 2018 at 12:08 PM WgxPlayup notifications@github.com wrote:

The REST API login only has two parameters: username and password. I think
the user ID and x-auth-token are returned by the server.
If I used the LDAP to login to the server, is it the reason that I
received 401?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/RocketChat/Rocket.Chat/issues/11411#issuecomment-405159635,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AH1ikrOREc65h6Sp4v5bfxvjMZIkmoJ8ks5uHDTygaJpZM4VIwzu
.

Sure, I have already registered on the server. I can login successfully with the browser.
The problem is how to use its credentials to pass in to the API call or need to do some related settings on the server?

Did you try this out :
https://rocket.chat/docs/developer-guides/rest-api/authentication/login/

On Mon, Jul 16, 2018 at 1:19 PM WgxPlayup notifications@github.com wrote:

Sure, I have already registered on the server. I can login successfully
with the browser.
The problem is how to use its credentials to pass in to the API call or
need to do some related settings on the server?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/RocketChat/Rocket.Chat/issues/11411#issuecomment-405171031,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AH1ikknkT8MV3z3ygRNqqsp_bwvDwHqaks5uHEWYgaJpZM4VIwzu
.

Thank you for your reply.
Yes, I tried, but the following result is returned.
{
"status": "error",
"error": "Unauthorized",
"message": "Unauthorized"
}
But as I said, I can login with the web.

If I am using the LDAP to login, is there any relationship with the 401?

Had the same problems a couple of days ago. You can‘t use any LDAP based user when using the API. You have two choices imho:

  • set login fallback to true (see also #7642)
  • register and use an additional local Rocket.Chat user for the API

See also #4961 for further work on this issue.

Thanks @dhoeld, that works. Had to create an extra API User too.

Why I cant use REST with LDAP-User?
I don't have admin rights to create a local user.

:-/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sta-szek picture sta-szek  Â·  3Comments

zeigerpuppy picture zeigerpuppy  Â·  3Comments

amayer5125 picture amayer5125  Â·  3Comments

lunitic picture lunitic  Â·  3Comments

mattlin picture mattlin  Â·  3Comments