Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

AttributeError: type object 'Create' has no attribute 'lower' #55

Open
cedricbonhomme opened this issue May 14, 2020 · 1 comment
Open

Comments

@cedricbonhomme
Copy link

I am using Flask-Swagger with Flask-MongoRest. Last versions, with Python 3.8.2.

I wanted to simply try this code from the README:

from flask import Flask, jsonify
from flask_swagger import swagger

app = Flask(__name__)

@app.route("/spec")
def spec():
    return jsonify(swagger(app))

then when I do GET http://127.0.0.1:5000/spec, the following error is displayed:

  File "/home/cedric/.cache/pypoetry/virtualenvs/stats-api-7Yf7ZOUq-py3.8/lib/python3.8/site-packages/flask_swagger.py", line 178, in <lambda>
    and verb in map(lambda m: m.lower(), endpoint.methods) \
AttributeError: type object 'Create' has no attribute 'lower'

I fixed my issue by changing this code:
https://github.com/gangverk/flask-swagger/blob/master/flask_swagger.py#L177-L179

to

if hasattr(endpoint, 'methods') \
                    and verb in map(lambda m: m.method.lower(), endpoint.methods) \	
                    and hasattr(endpoint.view_class, verb):

Since actually here m is an object, not a string. m.method is a string. It also works with str(m).lower().

With this change, it works quite well.

If you want I can create a fix which will works with m.lower() and m.method.lower() and make a pull request.

Or do you thing the issue is on the side of Flask-MongoRest ?

@atlithorn
Copy link
Contributor

I imagine this is because flask-swagger was originally built for Flask-RESTful and later retrofitted for vanilla Flask.
If a light change like you're suggesting will make this work for more frameworks I'm more than happy to look at that.

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

2 participants