asyrjasalo / RESTinstance

Robot Framework library for RESTful JSON APIs
https://pypi.org/project/RESTinstance
GNU Lesser General Public License v3.0
209 stars 83 forks source link

SchemaGenerationError: Could not find matching type for object #37

Closed nigotiator closed 6 years ago

nigotiator commented 6 years ago

This very simple GET test fails in Windows10 (Python 2.7.15) but it works with Ubuntu 16.04 (Python 2.7.12). Fails in Windows with SchemaGenerationError: Could not find matching type for object: 1536489510350L

Test was run in virtualenv in both systems and following packages were only installed by pip:

Test uses Liikennevirasto's open api to get the vessel location --> Can be easily tested with Curl or with browser: curl -X GET --header 'Accept: application/json' 'https://meri.digitraffic.fi/api/v1/locations/latest/230629000'

Test case:

*** Settings ***
Library           REST    https://meri.digitraffic.fi

*** Test Cases ***
Get
    Set Headers    {"Accept":"application/json;charset=UTF-8","User-Agent":"curl/7.47.0"}
    REST.Get    /api/v1/locations/latest/230181000    validate=true

Traceback:

Traceback (most recent call last):
  File "C:\temp\testi\lib\site-packages\REST\keywords.py", line 145, in get
    return self._request(endpoint, request, validate)['response']
  File "C:\temp\testi\lib\site-packages\REST\keywords.py", line 494, in _request
    instance = self._instantiate(request, response, validate)
  File "C:\temp\testi\lib\site-packages\REST\keywords.py", line 517, in _instantiate
    schema['response']['body'] = self._new_schema(response['body'])
  File "C:\temp\testi\lib\site-packages\REST\keywords.py", line 553, in _new_schema
    builder.add_object(value)
  File "C:\temp\testi\lib\site-packages\genson\schema\builder.py", line 64, in add_object
    self._root_node.add_object(obj)
  File "C:\temp\testi\lib\site-packages\genson\schema\node.py", line 50, in add_object
    schema_generator.add_object(obj)
  File "C:\temp\testi\lib\site-packages\genson\schema\generators\object.py", line 56, in add_object
    self._properties[prop].add_object(subobj)
  File "C:\temp\testi\lib\site-packages\genson\schema\node.py", line 50, in add_object
    schema_generator.add_object(obj)
  File "C:\temp\testi\lib\site-packages\genson\schema\generators\array.py", line 42, in add_object
    self._items.add_object(item)
  File "C:\temp\testi\lib\site-packages\genson\schema\node.py", line 50, in add_object
    schema_generator.add_object(obj)
  File "C:\temp\testi\lib\site-packages\genson\schema\generators\object.py", line 56, in add_object
    self._properties[prop].add_object(subobj)
  File "C:\temp\testi\lib\site-packages\genson\schema\node.py", line 50, in add_object
    schema_generator.add_object(obj)
  File "C:\temp\testi\lib\site-packages\genson\schema\generators\object.py", line 56, in add_object
    self._properties[prop].add_object(subobj)
  File "C:\temp\testi\lib\site-packages\genson\schema\node.py", line 49, in add_object
    schema_generator = self._get_generator_for_object(obj)
  File "C:\temp\testi\lib\site-packages\genson\schema\node.py", line 114, in _get_generator_for_object
    return self._get_generator_for_('object', obj)
  File "C:\temp\testi\lib\site-packages\genson\schema\node.py", line 146, in _get_generator_for_
    kind, schema_or_obj))
hidebear commented 6 years ago

I got this problem too, it's occurred in Win 10 (Python 2.7.15 and robot 3.0.4) and Win7 (Python 2.7.13 and robot 3.0.4). But there's no such issue in Fedora (Python 2.7.15 and robot 3.0.4).

After a few tries, I found that under Python 3 (my environment is Python 3.7.0 and robot 3.0.4) will be work in Windows. (but it's not a solution, it's a workaround)

asyrjasalo commented 6 years ago

@hidebear: Using Python 2 (over 3) is a workaround, not a solution.

Anyway, I am interested in the problem so I'll see if I can reproduce this on Windows 10.

asyrjasalo commented 6 years ago

Could not reproduce.

kanchi240 commented 5 years ago

@asyrjasalo I meet the same problem, my response has a filed named registerTime, which value will be a long type when used response.json() and lead this problem, I print response.json(), response.text, response.content, result is below:

response.json(): {u'message': u'\u6210\u529f', u'code': u'100000', u'data': {u'mobileNumber': u'15252896407', u'channelUserKey': u'5||eyJhbGciOiJIUzUxMiJ9.eyJjcmVhdGVkIjoxNTQ1MTgyNDYwMTk1LCJleHAiOjE1NDU3ODcyNjAsInVzZXJJZCI6IjM0MDAwMjEzIn0.I706vOZeIORzuv92AKIQq1IvFq4JTJe4-VGVggeT5RTDpw5O3TZDobbdjkuxamaIHgU1hpN3kiwm42WTUtITg', u'weixinAvatar': None, u'unionId': None, u'userId': u'34000213', u'registerTime': 1545182459000L, u'bindingMobileNumber': True, u'userSig': u'eJxFkNFOgzAUhtFW41pCyVosgsGBllGnGxZ1JsGoWxHoDSloMT47usaiTfn4v9ycr7--DiH7f6ukBIqVmjmqsp5cJBza2PLUFxVtSaKxNjSilBaKETVwP0wgCCMMXERegfQsWFhhrsousZQLD7xwY4mTB7fInSp1RHZHdI2qxv0u1GPpPThH2e8TgIm65LIB-jdmxyIt5CWLcoKXHwGb0eRfrh0c0uhPMN3itfzroeyvn9HGdfrxfT1r1XKsapitdy1w9aBmLiYaOm6LeRQHxPMX6Is1FopmfJ7T9*L469Vw4', u'nickName': u'15252896407'}}

response.text: {"code":"100000","message":"成功","data":{"userId":"34000213","channelUserKey":"5||eyJhbGciOiJIUzUxMiJ9.eyJjcmVhdGVkIjoxNTQ1MTgyNDYwMTk1LCJleHAiOjE1NDU3ODcyNjAsInVzZXJJZCI6IjM0MDAwMjEzIn0.I706vOZeIORzuv92AKIQq1IvFq4JTJe4-VGVggeT5RTDpw5O3TZDobbdjkuxamaIHgU1hpN3kiwm42WTUtITg","weixinAvatar":null,"nickName":"15252896407","unionId":null,"mobileNumber":"15252896407","userSig":"eJxFkNFOgzAUhtFW41pCyVosgsGBllGnGxZ1JsGoWxHoDSloMT47usaiTfn4v9ycr7--DiH7f6ukBIqVmjmqsp5cJBza2PLUFxVtSaKxNjSilBaKETVwP0wgCCMMXERegfQsWFhhrsousZQLD7xwY4mTB7fInSp1RHZHdI2qxv0u1GPpPThH2e8TgIm65LIB-jdmxyIt5CWLcoKXHwGb0eRfrh0c0uhPMN3itfzroeyvn9HGdfrxfT1r1XKsapitdy1w9aBmLiYaOm6LeRQHxPMX6Is1FopmfJ7T9*L469Vw4","registerTime":1545182459000,"bindingMobileNumber":true}}

response.content: {"code":"100000","message":"鎴愬姛","data":{"userId":"34000213","channelUserKey":"5||eyJhbGciOiJIUzUxMiJ9.eyJjcmVhdGVkIjoxNTQ1MTgyNDYwMTk1LCJleHAiOjE1NDU3ODcyNjAsInVzZXJJZCI6IjM0MDAwMjEzIn0.I706vOZeIORzuv92AKIQq1IvFq4JTJe4-VGVggeT5RTDpw5O3TZDobbdjkuxamaIHgU1hpN3kiwm42WTUtITg","weixinAvatar":null,"nickName":"15252896407","unionId":null,"mobileNumber":"15252896407","userSig":"eJxFkNFOgzAUhtFW41pCyVosgsGBllGnGxZ1JsGoWxHoDSloMT47usaiTfn4v9ycr7--DiH7f6ukBIqVmjmqsp5cJBza2PLUFxVtSaKxNjSilBaKETVwP0wgCCMMXERegfQsWFhhrsousZQLD7xwY4mTB7fInSp1RHZHdI2qxv0u1GPpPThH2e8TgIm65LIB-jdmxyIt5CWLcoKXHwGb0eRfrh0c0uhPMN3itfzroeyvn9HGdfrxfT1r1XKsapitdy1w9aBmLiYaOm6LeRQHxPMX6Is1FopmfJ7T9*L469Vw4","registerTime":1545182459000,"bindingMobileNumber":true}}

kanchi240 commented 5 years ago

This problem probably caused by when the number field value in the response is exceed the sys.maxint when using python2, everything is ok after upgrade to python 3.

iamdhruvanand commented 5 years ago

This workaround works with which exact versions of python and robot please?

kanchi240 commented 5 years ago

@iamdhruvanand update to the newest python3.