tagreader-python icon indicating copy to clipboard operation
tagreader-python copied to clipboard

Searching for "11#35-DENS" on MO-IP21AB causes Requests.JSONDecodeError

Open HSYSL opened this issue 3 years ago • 5 comments

Using the following code to search for 11#35-DENS causes Requests.JSONDecodeError.

import os
import datetime
import tagreader


def connect_to_aspen():
	print("Venter på svar frå aspen")
	API = "aspenone"
	sources = tagreader.list_sources(API)
	if "MO-IP21AB" not in sources:
		print("Kunne ikkje koble til MO-IP21AB")
		os._exit(0)
	else:
		source = "MO-IP21AB"
	client = tagreader.IMSClient(source, API)
	client.connect()
	return client

if __name__ == "__main__":
    pp = "11#35-DENS"
    end = datetime.date.today()
    start = end + datetime.timedelta(days=-30)
    client = connect_to_aspen()
    m = client.search(pp)
    print(m)

Backtrace:

Traceback (most recent call last):
  File "C:\Users\hsysl\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\models.py", line 972, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\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 "f:\tettleiksmeister\main.py", line 24, in <module>
    m = client.search(pp)
  File "C:\Users\hsysl\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\tagreader\clients.py", line 273, in search
    return self.handler.search(tag, desc)
  File "C:\Users\hsysl\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\tagreader\web_handlers.py", line 349, in search
    description = self._get_tag_description(tagname)
  File "C:\Users\hsysl\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\tagreader\web_handlers.py", line 403, in _get_tag_description  
    j = res.json()
  File "C:\Users\hsysl\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\models.py", line 976, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

HSYSL avatar Jul 25 '22 13:07 HSYSL

Hi Håvard,

I am trying to replicate the error on my side, but I am only getting an empty list output. image

If you search for: pp="*"

Do you get the same error? I am trying to deduct if it's tag specific or search function doesn't work on your end.

Adam

AdamZalewski avatar Jul 28 '22 12:07 AdamZalewski

Hi,

searching for pp="*" causes the same error. Searching for pp="11-TI-050", a tag that does not exist returns an empty list.

HSYSL avatar Aug 01 '22 06:08 HSYSL

Hi,

I don't have access to the MO asset as we have only looked after the offshore assets. I will rise a request for access so I can replicate the error and see what value is the server passing over to cause the error.

AdamZalewski avatar Aug 02 '22 14:08 AdamZalewski

Hi,

I got access to the PI of MO asset. I am able to search and see the tag. However, a part of the code is sending a request to the server to get_tag_description and getting an error message returned from server. Will investigate further, however, it might be PI server issue rather than tagreader.

AdamZalewski avatar Aug 22 '22 12:08 AdamZalewski

Hi,

There was a server side error coming in when calling descriptions. The code should now search without crashing with next update.

Kind Regards, Adam

AdamZalewski avatar Aug 31 '22 07:08 AdamZalewski