Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

APIV2 Error No JSON object could be decoded


#1

We have two instances of testrail, on one instance I am able to access testrail from api but in another instance I am getting the below mentioned error. Please help me to fix this issue

File “C:\Users*\MyGitHub\testrail.py”, line 35, in send_get
return self.__send_request(‘GET’, uri, None)
File “C:\Users*\MyGitHub\testrail.py”, line 69, in _send_request
result = json.loads(response)
File "C:\WinPython\python-2.7.5.amd64\lib\json_init
.py", line 338, in loads
return _default_decoder.decode(s)
File “C:\WinPython\python-2.7.5.amd64\lib\json\decoder.py”, line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “C:\WinPython\python-2.7.5.amd64\lib\json\decoder.py”, line 383, in raw_decode
raise ValueError(“No JSON object could be decoded”)
ValueError: No JSON object could be decoded


#2

Hello Prakaran,

Thanks for your posting! In addition to an error/message, the API also returns an HTTP status code which should help in this case. Could you please send the full response via email to contact@gurock.com for us to review?

Cheers,
Tobias


#3

Hi Tobias,

This is the complete error message which I got from python api call. I dont see any other HTTP error messages. By the way how can I use kerberos authentication instead of username and password. The one which uses username and password is working fine with python call but another testrail instance which uses kerberos / LDAP authentication is not woking when I pass my user name and ldap password.


#4

Hello Prakaran,

Thanks for the additional details! You could take a look at the send_request method in the API binding directly and print the response object and possible exception e (e.g. via pprint or similar). Could you also let me know which TestRail version you use?

Regarding the authentication: the API also fully supports external authentication if you’ve configured TestRail to use it and please make sure that the API is enabled under Administration > Site Settings > API.

Cheers,
Tobias


#5

we use TestRail v4.0.0.3251 and yes API is enabled. Is this because we use kerberos/LDAP authentication. I am sure that I use correct password

here is the response

401 Unauthorized

Unauthorized

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.


#6

Hi Prakaran,

Thanks for the additional details. The current TR version always returns a JSON response and I would recommend looking into updating to the latest TR version. That said, the 401/403 response that is returned indicates either an authentication or permission error and I would recommend reviewing your username and password as well as permissions for the project you are trying to access. I can also recommend updating to the latest TR version and the response would then include additional details why the API requests was denied.

I hope this helps!

Cheers,
Tobias


#7

Hi tgurock,

we have updated to TestRail v5.2.0.3452, I am unable to access neither with API key nor password. I do have permissions for the testrail instance.

Traceback (most recent call last):

401 Unauthorized

Unauthorized

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong result = json.loads(response) credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.


#8

Hi Prakaran,

Have you already enabled the API in TestRail’s administration area (Administration > Site Settings > API)? You can use your regular username and password for the API integration or add a separate API key on your My Settings page.

Cheers,
Tobias


#9

here is the screen shot it was enabled already but still getting this error,
Note: I have admin access
Used the username and API key generated

Unauthorized

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

I see the following in system logs

[Swift_ConnectionException] No authentication mechanisms were tried
since the server did not support any of the ones loaded. Loaded
authenticators: [LOGIN, CRAM-MD5, PLAIN]

								at Swift_Connection_SMTP->runAuthenticators (SMTP.php:332)

								at Swift_Connection_SMTP->postConnect (Swift.php:265)

								at Swift->handshake (Swift.php:221)

								at Swift->connect (Swift.php:102)

								at Swift->__construct (email.php:120)

								at Email_library->_try_send (email.php:78)

								at Email_library->send (email.php:117)

								at email::send (notifications.php:110)

								at Notifications_job->_send_message (notifications.php:65)

								at Notifications_job->_process_message (notifications.php:52)

								at Notifications_job->run (tasks.php:174)

								at Tasks_controller->_run_job (tasks.php:143)

								at Tasks_controller->_process_job (tasks.php:61)

								at Tasks_controller->_run (tasks.php:50)

								at Tasks_controller->index (controller.php:126)

								at Controller->_invoke_cli (controller.php:116)

								at Controller->_invoke (gizmo.php:107)

								at require_once (index.php:106)

								at require_once (task.php:49)

								at include (testrail-task.php:5)

#10

Hi Prakaran,

This looks like an issue with the email configuration and/or sending emails. Can you try to check your email settings on the Email tab? You can also try to disable email notifications (temporarily if you want) to see if this makes a difference.

Cheers,
Tobias


#11

Yes I disabled email notifications and tried but still getting the same error.


#12

Hi Prakaran,

Do you use a self-hosted TestRail installation or TestRail Cloud? If self-hosted, please make sure that the web server configuration allows HTTP authentication and does not remove any credentials before the requests reaches TestRail.

Cheers,
Tobias


#13

I am getting this error now

[AuthException] Authentication failed: invalid or missing user/password or session cookie.

								---

								Details: <missing>

								File: /local/apollo/var/env/TestRailServer/server-root/testrail/sys/helpers/ex.php

								Line: 25

								Status Code: 500

								Host: ******.com

								Uri: /api.php?/api/v2/get_users/ (GET)

								---

								Browser: curl/7.45.0

								PHP: 5.4.27

								Server: Linux 2.6.18-kaos_fleet-1108-prod.2 #1 SMP Wed Oct 19 17:27:18 UTC 2011 x86_64

								---

								Trace:

								at ex::raise (ex.php:25)

								at ex::raise (ex.php:77)

								at ex::raiset (v2.php:143)

								at V2_controller->_check_user (v2.php:19)

								at V2_controller->_init (gizmo.php:106)

								at require_once (index.php:106)

								at include (api.php:5)

#14

Hi Prakaran,

Thanks for your reply. This is the same authentication error that was returned previously and means that you either use an incorrect username/password or API key, or that your web server configuration does not pass the HTTP authentication credentials to TestRail. Do you use your regular password or an API key? Can you check/verify the username/password/API key/web server configuration again?

Cheers,
Tobias


#15

can you please help me with webserver configuration? Headers are being stripped in apache


#16

Hi Prakaran,

Not sure what’s causing this to be honest but we would recommend using the standard packages of your Linux distribution to install Apache + PHP and this setup works fine out of the box. Do you have any non-standard Apache modules installed? Have you maybe activated mod_rewrite? This is not needed for TestRail and can remove HTTP authentication headers.

I hope this helps!

Cheers,
Tobias