0

I am having an issue with a simple body parsing using pyswagger (library to test OpenAPI compliant APIs).

Here is my script:

import os
from dotenv import load_dotenv, find_dotenv
from pyswagger import App, Security
from pyswagger.contrib.client.requests import Client

# load my security token
load_dotenv(find_dotenv())
api_key = os.environ.get('HELLO_SWAGGER_API_KEY', 'xxx')
hello_swagger_json = 'https://europewest.services.azureml.net/subscriptions/300c8e706bdd414aa1c215ceb2b5a465/services/363818fa1c4a4d0b9d5c03a3dc6f1dfe/swagger.json'

# adapted from pyswagger quick start
app = App._create_(hello_swagger_json)
auth = Security(app)
auth.update_with('api_key', api_key)
client = Client(auth)

# this produces a dictionary exactly as in the schema example for 'execute' operation
hello_body = dict(Inputs=dict(input1=[dict(name="mission-liao")]), GlobalParameters=dict())

# submit execute post request
req, resp = app.op['execute'](body=hello_body)

which give me this error when executing last line:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\spec\v2_0\objects.py", line 283, in __call__
    _convert_parameter(final(p))
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\spec\v2_0\objects.py", line 264, in _convert_parameter
    c = p._prim_(v, self._prim_factory, ctx=dict(read=False))
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\spec\v2_0\objects.py", line 184, in _prim_
    return prim_factory.produce(self.schema, v, ctx) if i == 'body' else prim_factory.produce(self, v, ctx)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\__init__.py", line 200, in produce
    val = ret.apply_with(obj, val, ctx)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\_model.py", line 29, in apply_with
    self[k] = ctx['factory'].produce(pobj, v)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\__init__.py", line 196, in produce
    val = _2nd(obj, ret, val, ctx)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\comm.py", line 40, in _2nd_pass_obj
    return ret.apply_with(obj, val, ctx)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\_model.py", line 29, in apply_with
    self[k] = ctx['factory'].produce(pobj, v)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\__init__.py", line 196, in produce
    val = _2nd(obj, ret, val, ctx)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\comm.py", line 40, in _2nd_pass_obj
    return ret.apply_with(obj, val, ctx)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\_array.py", line 48, in apply_with
    self.extend(map(functools.partial(ctx['factory'].produce, obj.items), val))
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\__init__.py", line 200, in produce
    val = ret.apply_with(obj, val, ctx)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\_model.py", line 29, in apply_with
    self[k] = ctx['factory'].produce(pobj, v)
  File "P:\Development\Anaconda3\envs\tgml36\lib\site-packages\pyswagger\primitives\__init__.py", line 192, in produce
    raise ValueError('Can\'t resolve type from:(' + str(obj.type) + ', ' + str(obj.format) + ')')
ValueError: Can't resolve type from:(String, )

I cannot really understand if there is something I am doing wrong or if this is a bug. This is actually a very simple example I was trying to build because I am having an issue with authentication in a more complex example, but while in the more complex example the body parsing does not raise errors, here I am having problems even before sending a request!

The script should be reproducible (swagger.json should be accessible from the url in the script, if not I can attach it) and I have logging info only when running the command app = App._create_(hello_swagger_json) (so this too should be reproducible too using the above script).

The webservice that I am trying to test is a simple Web service built with Azure ML Studio (which provides a Swagger API, the reason why I found out about Swagger in the first place).

I am running with pyswagger version 0.8.39.

2
  • 1
    Not sure if this is related, but this swagger.json file has some syntax errors, which you can see if you load it into editor.swagger.io. Specifically: 1) query strings must not be part of paths and should be defined as in: query parameters instead. 2) type: String should be type: string (lowercase). 3) Path parameters are missing type. Commented Oct 19, 2018 at 8:19
  • Thanks, I will look into it. It was automatically generated by Azure ML Studio, so I assumed it was generated correctly... Commented Oct 19, 2018 at 9:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.