Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requests.exceptions.JSONDecodeError in pytest-reportportal v5.2.1 #225

Closed
manvendravsingh opened this issue Aug 7, 2023 · 10 comments
Closed

Comments

@manvendravsingh
Copy link

manvendravsingh commented Aug 7, 2023

I have update the python-reportportal to latest build. and now I am facing following issue-

PS

C:\Users*****\PycharmProjects\MyProject> pytest --reportportal

---------------------------- live log sessionstart ----------------------------
rp_requests.py 83 WARNING Report Portal None request failed
Traceback (most recent call last):
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\json_init_.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users*\AppData\Local\Programs\Python\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)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_requests.py", line 76, in make
timeout=self.http_timeout)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_responses.py", line 64, in init
self._data = self.get_json(data)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_responses.py", line 74, in _get_json
return data.json()
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
rp_requests.py 83 WARNING Report Portal None request failed
Traceback (most recent call last):
File "C:\Users*****\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 971, in json
return complexjson.loads(self.text, kwargs)
File "C:\Users****\AppData\Local\Programs\Python\Python37\lib\json_init.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users*\AppData\Local\Programs\Python\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)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_requests.py", line 76, in make
timeout=self.http_timeout)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_responses.py", line 64, in init
self._data = self._get_json(data)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_responses.py", line 74, in _get_json
return data.json()
File "C:\Users*****\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
============================= test session starts =============================
platform win32 -- Python 3.7.0, pytest-3.10.1, py-1.11.0, pluggy-1.0.0 -- C:\Users*\AppData\Local\Programs\Python\Python37\python.exe
cachedir: .pytest_cache
metadata: {'Python': '3.7.0', 'Platform': 'Windows-10-10.0.19041-SP0', 'Packages': {'pytest': '3.10.1', 'pluggy': '1.0.0'}, 'Plugins': {'depends': '1.0.1', 'html': '1.22.0', 'metadata'
: '2.0.4', 'reportportal': '5.2.1'}}
rootdir: C:\Users******\PycharmProjects\MyProject, inifile: pytest.ini
plugins: depends-1.0.1, html-1.22.0, metadata-2.0.4, reportportal-5.2.1
collected 2 items

----------------------------- live log collection -----------------------------
rp_requests.py 83 WARNING Report Portal None request failed
Traceback (most recent call last):
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\json_init_.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\masing\AppData\Local\Programs\Python\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)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_requests.py", line 76, in make
timeout=self.http_timeout)
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_responses.py", line 64, in init
self._data = self._get_json(data)
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_responses.py", line 74, in _get_json
return data.json()
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

test_sample.py::TestSample::test_sampleTest1
------------------------------- live log setup --------------------------------
conftest.py 18 INFO Test Started
-------------------------------- live log call --------------------------------
test_sample.py 10 INFO This is Sample Test 1
PASSED [ 50%]
------------------------------- live log finish -------------------------------
client.py 248 WARNING Attempt to finish non-existent item
rp_requests.py 83 WARNING Report Portal None request failed
Traceback (most recent call last):
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\json_init_.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\masing\AppData\Local\Programs\Python\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)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_requests.py", line 76, in make
timeout=self.http_timeout)
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_responses.py", line 64, in init
self._data = self._get_json(data)
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_responses.py", line 74, in _get_json
return data.json()
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

test_sample.py::TestSample::test_sampleTest2
-------------------------------- live log call --------------------------------
test_sample.py 14 INFO This is sample Test 2
PASSED [100%]
------------------------------ live log teardown ------------------------------
conftest.py 20 INFO Test End
------------------------------- live log finish -------------------------------
client.py 248 WARNING Attempt to finish non-existent item
--------------------------- live log sessionfinish ----------------------------
client.py 205 WARNING Attempt to finish non-existent launch
rp_requests.py 83 WARNING Report Portal None request failed
Traceback (most recent call last):
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\json_init_.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\masing\AppData\Local\Programs\Python\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)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_requests.py", line 76, in make
timeout=self.http_timeout)
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_responses.py", line 64, in init
self._data = self._get_json(data)
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_responses.py", line 74, in _get_json
return data.json()
File "C:\Users\masing\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

========================== 2 passed in 1.38 seconds ===========================

I am using Python version 3.7.0. Please help.

@HardNorth
Copy link
Member

@manvendravsingh that means your server didn't response with a JSON. Could you please describe how you configure your agent?

@manvendravsingh
Copy link
Author

manvendravsingh commented Aug 8, 2023

I am using demo report portal. I have update my pytest.ini with following settings.
rp_endpoint = https://demo.reportportal.io/asd
rp_api_key = ******************************************************
rp_project = default_personal
rp_launch = *********************

Then as suggested in readme I have created rp_logger -

from reportportal_client import RPLogger

@pytest.fixture(scope="session")
def rp_logger():
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.INFO)
    logging.setLoggerClass(RPLogger)
    return logger

and using this logger in my pytest Tests. as -

@pytest.mark.usefixtures("setup")   # Setup is just someother fixture printing Hi as of now. 
class TestSample:
    def test_sampleTest1(self,rp_logger):
        rp_logger.info("This is Sample Test 1")
        assert True

now I am executing the test cases using command - pytest --reportportal

Please let me know if I am missing something.

@rplevka
Copy link
Contributor

rplevka commented Aug 9, 2023

rp_endpoint = https://demo.reportportal.io/asd

remove the /asd.

@manvendravsingh
Copy link
Author

Thanks for reply. I am able to send test results on demo site now.

Now, I have applied same changes in live project and I am facing the same issue. The main difference is that, In my live project has reportportal is deployed our port 8080 so I have to use the rp_endpoint= http://myliveprojectsite.com:8080.
But when I doing this I am facing the same JsonDecodeError.
12:29:57 - [reportportal_client.core.rp_requests] - WARNING: Report Portal None request failed
Traceback (most recent call last):
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 971, in json
return complexjson.loads(self.text, kwargs)
File "C:\Users*
\AppData\Local\Programs\Python\Python37\lib\json_init_.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Users*
\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users*
\AppData\Local\Programs\Python\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)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_requests.py", line 76, in make
timeout=self.http_timeout)
File "C:\Users*
\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_responses.py", line 64, in init
self._data = self._get_json(data)
File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\site-packages\reportportal_client\core\rp_responses.py", line 74, in _get_json
return data.json()
File "C:\Users*
\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I have tried to connect without giving the port then server is refusing the connection. (as expected)

It seems like while parsing the port in endpoint JsonDecoder is failing. Please help .

@HardNorth
Copy link
Member

@manvendravsingh When I test the agent locally I also use port 8080 and that's cause no issue. So I would check that your instance actually working.

@rplevka
Copy link
Contributor

rplevka commented Aug 10, 2023

@manvendravsingh i'd rather have this issue closed as this is really only some misconfig.

Is your instance really reachable at the provided url (E.g. from a browser)?
Since this is a new deployment, have you updated the API token?

If you are still facing issues, please, kindly post theis kind of requests to the community slack.
Good luck and thanks for understanding.

@manvendravsingh
Copy link
Author

My instance is reachable. It is working fine with Python-reportportal 1.0.2 . I am trying to update to new version. Is it required to update the instance also ?

@HardNorth
Copy link
Member

@manvendravsingh So you are using custom solution, that explains a lot. I believe you need to double-check your URLs, there's no any different reason to get such error, except invalid URL (on working instance). Even incorrect credentials return JSON response.

@rplevka
Copy link
Contributor

rplevka commented Aug 14, 2023

@manvendravsingh you can place a breakpoint here and see what is inside the response (data.text).
That will give you a hint.
@HardNorth, we might wrap that inside a try-except block and append the text of the response in the Error to help users to figure out what is going on (in the future)

@HardNorth HardNorth transferred this issue from reportportal/agent-python-pytest Oct 30, 2023
@HardNorth
Copy link
Member

HardNorth commented Oct 30, 2023

@rplevka I don't like exposing responses on our level of abstraction, there are HTTP logging properties which is regulated by chosen HTTP clients, which should be responsible for that. But I added better JSONDecodeError logging for our response classes here:
https://github.com/reportportal/client-Python/blob/d9fe80a4589a99019b48e5b618a4b1df0bd00de7/reportportal_client/core/rp_responses.py#L44C5-L44C35

I believe this resolves the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants