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

Attribute error while making a request with swagger spec 2.0 #171

Open
kvnamipara opened this issue Jan 22, 2019 · 2 comments
Open

Attribute error while making a request with swagger spec 2.0 #171

kvnamipara opened this issue Jan 22, 2019 · 2 comments

Comments

@kvnamipara
Copy link

With using open APIs spec v2 of GitHub using pyswagger, I am unable to get desired response.

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/kvnamipara/Desktop/summer/staging/venv3/lib/python3.6/site-packages/pyswagger/contrib/client/requests.py", line 76, in request
    header=rs.headers,
  File "/Users/kvnamipara/Desktop/summer/staging/venv3/lib/python3.6/site-packages/pyswagger/io.py", line 417, in apply_with
    self.__data = r.schema._prim_(data, self.__op._prim_factory, ctx=dict(read=True))
  File "/Users/kvnamipara/Desktop/summer/staging/venv3/lib/python3.6/site-packages/pyswagger/spec/v2_0/objects.py", line 92, in _prim_
    return prim_factory.produce(self, v, ctx)
  File "/Users/kvnamipara/Desktop/summer/staging/venv3/lib/python3.6/site-packages/pyswagger/primitives/__init__.py", line 196, in produce
    val = _2nd(obj, ret, val, ctx)
  File "/Users/kvnamipara/Desktop/summer/staging/venv3/lib/python3.6/site-packages/pyswagger/primitives/comm.py", line 40, in _2nd_pass_obj
    return ret.apply_with(obj, val, ctx)
  File "/Users/kvnamipara/Desktop/summer/staging/venv3/lib/python3.6/site-packages/pyswagger/primitives/_array.py", line 48, in apply_with
    self.extend(map(functools.partial(ctx['factory'].produce, obj.items), val))
  File "/Users/kvnamipara/Desktop/summer/staging/venv3/lib/python3.6/site-packages/pyswagger/primitives/__init__.py", line 196, in produce
    val = _2nd(obj, ret, val, ctx)
  File "/Users/kvnamipara/Desktop/summer/staging/venv3/lib/python3.6/site-packages/pyswagger/primitives/comm.py", line 40, in _2nd_pass_obj
    return ret.apply_with(obj, val, ctx)
  File "/Users/kvnamipara/Desktop/summer/staging/venv3/lib/python3.6/site-packages/pyswagger/primitives/_model.py", line 23, in apply_with
    for k, v in six.iteritems(val):
  File "/Users/kvnamipara/Desktop/summer/staging/venv3/lib/python3.6/site-packages/six.py", line 587, in iteritems
    return iter(d.items(**kw))
AttributeError: 'str' object has no attribute 'items'

On debugging I found that, Api call is made correctly and correct response has been fetched, but then there is error while parsing the response object to pyswagger response object. Can anyone explain me what and where it is going wrong?
Thanks.

@kvnamipara kvnamipara changed the title Attribute error while requesting Attribute error while making a request with openAPI spec 2.0 Jan 22, 2019
@kvnamipara kvnamipara changed the title Attribute error while making a request with openAPI spec 2.0 Attribute error while making a request with swagger spec 2.0 Jan 22, 2019
@loganlinn
Copy link

I recently encountered a error: AttributeError: 'list' object has no attribute 'items'

Turns out that one one of the properties in the spec (also 2.0) was marked type: "object" when it should have been type: "array".

So, I would compare your schema against the response data to see if a property is declared as type: "object" when it's actually a string.

Maybe some simple error handling could be added in a future release of this library to add better error messages when a primitive factory raises exception

@renamed
Copy link

renamed commented Sep 2, 2019

After spending a long and hard time on it, you sir saved my life!

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

No branches or pull requests

3 participants