Reputation: 81
I'm trying to make a microservice with python, I'm following this tutorial
But I'm getting this error:
"flask_app.py", line 115, in run
raise Exception('Server {} not recognized'.format(self.server))
Exception: Server 9090 not recognized
Project structure:
App.py file code
from connexion.resolver import RestyResolver
import connexion
if __name__ == '__main__':
app = connexion.App(__name__, 9090, specification_dir='swagger/')
app.add_api('my_super_app.yaml', resolver=RestyResolver('api'))
app.run()
my_super_app.yaml file code
swagger: "2.0"
info:
title: "My first API"
version: "1.0"
basePath: /v1.0
paths:
/items/:
get:
responses:
'200':
description: 'Fetch a list of items'
schema:
type: array
items:
$ref: '#/definitions/Item'
definitions:
Item:
type: object
properties:
id:
type: integer
format: int64
name: { type: string }
items.py file code
items = {
0: {"name": "First item"}
}
def search() -> list:
return items
Upvotes: 2
Views: 773
Reputation: 32
There are plenty of microservice frameworks in Python that would simplify a lot the code you have to write.
Try for example pymacaron (http://pymacaron.com/). Here is an example of an helloworld api implemented with pymacaron: https://github.com/pymacaron/pymacaron-helloworld
A pymacaron service requires you only to: (1) write a swagger specification for your api (which is always a good starting point, whatever language you are using). Your swagger file describes the get/post/etc calls of your api and which objects (json dicts) they get and return, but also which python method in your code that implement the endpoint. (2) and implement your endpoints' methods.
Once you have done that, you get loads of things for free: you can package your code as a docker container, deploy it to amazon beanstalk, start asynchronous tasks from within your api calls, or get the api documentation with no extra work.
Upvotes: -1
Reputation: 81
ok... i was able to solve this problem... the problem is in app.py, you must specify the variable port:
INCORRECT
app = connexion.App(__name__, 9090, specification_dir='swagger/')
CORRECT
app = connexion.App(__name__, port=9090, specification_dir='swagger/')
Upvotes: 6