Gcloud app engine does not work

Hello,

Following the instruction deploying a model into production here, I got an error after typing:
python app/server.py serve

INFO: Started server process [17137]
INFO: Waiting for application startup.
INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)
INFO: ('127.0.0.1', 51920) - "GET / HTTP/1.1" 200
INFO: ('127.0.0.1', 51921) - "GET /static/client.js HTTP/1.1" 200
INFO: ('127.0.0.1', 51920) - "GET /static/style.css HTTP/1.1" 200
INFO: ('127.0.0.1', 51920) - "GET /favicon.ico HTTP/1.1" 404
INFO: ('127.0.0.1', 51920) - "POST /analyze HTTP/1.1" 500
ERROR: Exception in ASGI application
Traceback (most recent call last):
  File "/Users/phuongphuc/anaconda/envs/gg_app_engine_3.7/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 372, in run_asgi
    result = await asgi(self.receive, self.send)
  File "/Users/phuongphuc/anaconda/envs/gg_app_engine_3.7/lib/python3.7/site-packages/starlette/middleware/errors.py", line 125, in asgi
    raise exc from None
  File "/Users/phuongphuc/anaconda/envs/gg_app_engine_3.7/lib/python3.7/site-packages/starlette/middleware/errors.py", line 103, in asgi
    await asgi(receive, _send)
  File "/Users/phuongphuc/anaconda/envs/gg_app_engine_3.7/lib/python3.7/site-packages/starlette/middleware/cors.py", line 138, in simple_response
    await inner(receive, send)
  File "/Users/phuongphuc/anaconda/envs/gg_app_engine_3.7/lib/python3.7/site-packages/starlette/exceptions.py", line 74, in app
    raise exc from None
  File "/Users/phuongphuc/anaconda/envs/gg_app_engine_3.7/lib/python3.7/site-packages/starlette/exceptions.py", line 63, in app
    await instance(receive, sender)
  File "/Users/phuongphuc/anaconda/envs/gg_app_engine_3.7/lib/python3.7/site-packages/starlette/routing.py", line 41, in awaitable
    response = await func(request)
  File "app/server.py", line 53, in analyze
    return JSONResponse({'result': learn.predict(img)[0]})
  File "/Users/phuongphuc/anaconda/envs/gg_app_engine_3.7/lib/python3.7/site-packages/starlette/responses.py", line 43, in __init__
    self.body = self.render(content)
  File "/Users/phuongphuc/anaconda/envs/gg_app_engine_3.7/lib/python3.7/site-packages/starlette/responses.py", line 183, in render
    separators=(",", ":"),
  File "/Users/phuongphuc/anaconda/envs/gg_app_engine_3.7/lib/python3.7/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/Users/phuongphuc/anaconda/envs/gg_app_engine_3.7/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/Users/phuongphuc/anaconda/envs/gg_app_engine_3.7/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/Users/phuongphuc/anaconda/envs/gg_app_engine_3.7/lib/python3.7/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Category is not JSON serializable

Anyone has faced the same issue? Please help on it

Does your server run locally? https://course.fast.ai/deployment_google_app_engine.html#local-testing

I was having the same problem. This solved it: Issues with deployment on google app engine example

1 Like

The simple solution is to change the Category data type which is returned by learn.predict to String .

JSONResponse({'result':learn.predict(img)[0]} to
JSONResponse({'result':str(learn.predict(img)[0])}