Why can't I start it successfully? How to use it correctly?


#1

I installed APIStar then copy the code from the Quick Star page.
I run it and got an error.

TypeError: issubclass() arg 1 must be a class

Why is this happening?


#2

Python 3.7. The 3.7 interpreter has a backwards incompatible change that is producing that error. There is a pull request that has been waiting for a few weeks now to to fix it…

For now you will need to monkey patch a function in the type system before you start up your code.

# MONKEY PATCHING FOR 37 SUPPORT
from abc import ABCMeta
from apistar.types import TypeMetaclass


def subclass_37_fix(cls, subclass):
    try:
        return ABCMeta.__subclasscheck__(cls, subclass)
    except TypeError:
        return False


TypeMetaclass.__subclasscheck__ = subclass_37_fix
# END MONKEY PATCH

from apistar import App, Route


def welcome(name=None):
    if name is None:
        return {'message': 'Welcome to API Star!'}
    return {'message': 'Welcome to API Star, %s!' % name}


routes = [
    Route('/', method='GET', handler=welcome),
]

app = App(routes=routes)

if __name__ == '__main__':
    app.serve('127.0.0.1', 5000, debug=True)