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

fix two errors in examples/apispec_example.py #596

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

billvsme
Copy link

If you run this example, errors will occur when you enter http://127.0.0.1:5000/apidocs/ and Execute /add and /random. I have fixed them.

/random

Starting from version 3.0, marshmallow directly returns serialized data after a dump, no longer having data.

Traceback (most recent call last):
  File "/Users/billvsme/.venv/openapi/lib/python3.9/site-packages/flask/app.py", line 2213, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/billvsme/.venv/openapi/lib/python3.9/site-packages/flask/app.py", line 2193, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/billvsme/.venv/openapi/lib/python3.9/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/billvsme/.venv/openapi/lib/python3.9/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/billvsme/.venv/openapi/lib/python3.9/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/billvsme/.venv/openapi/lib/python3.9/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/Users/billvsme/temp/flasgger/examples/apispec_example.py", line 50, in random_pet
    return jsonify(PetSchema().dump(pet).data)
AttributeError: 'dict' object has no attribute 'data'

/add

The error with /add is due to the fact that the POST method's body doesn't need to be specified in the view function, as its parameters are used in the URL instead. If you need to access the content of a POST's body, you can use request.data or requst.data within your view.

Traceback (most recent call last):
  File "/Users/billvsme/.venv/openapi/lib/python3.9/site-packages/flask/app.py", line 2213, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/billvsme/.venv/openapi/lib/python3.9/site-packages/flask/app.py", line 2193, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/billvsme/.venv/openapi/lib/python3.9/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/billvsme/.venv/openapi/lib/python3.9/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/billvsme/.venv/openapi/lib/python3.9/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/billvsme/.venv/openapi/lib/python3.9/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
TypeError: create_pet() missing 1 required positional argument: 'body'

@billvsme billvsme changed the title fix two errors examples/apispec_example.py fix two errors in examples/apispec_example.py Sep 19, 2023
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

Successfully merging this pull request may close these issues.

None yet

1 participant