Question: Error: AttributeError: module 'flask_openapi3.request' has no attribute 'method' #60
Unanswered
zhongli1990
asked this question in
Q&A
Replies: 1 comment
-
get and post should be used to two different endpoint,like: @app.get("/gpt/v1")
def get_gpt():
...
@app.post("/gpt/v1")
def post_gpt():
... |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Now for example, my previous flask API was changed to this flask-openapi style API, as below.
This code is running on a Python 3.9 docker in docker-compose. The API is:
============
openai_tag = Tag(name="GPTBot", description="API gateway for Bot services: GPT, ChatGPT")
class BodyGPT(BaseModel):
question: str
language: str
#@app.route("/gpt3/v1", methods=("GET", "POST")) --- this is the previous simple flask API
@app.post("/gpt3/v1", tags=[openai_tag]) # ----- this app is now the flask-openapi3 app
@app.get("/gpt3/v1", tags=[openai_tag])
def get_gpt3_answer(body: BodyGPT):
if request.method == "POST" or request.method == "GET": # ----- now the request has no "method" attr?
API_ENDPOINT="http://backend-services/gpt3/v1"
question = body.question or 'Hi'
lang = body.lang or 'English'
data={'question':question, 'language':lang}
r = requests.post(url=API_ENDPOINT, data=data)
return r.text, 200
=======================
The I got the error below in the running Docker: (BTW: the swagger UI is showing fine now, just the API relay is not working)
=============
File "/app/app.py", line 44, in get_gpt3_answer
if request.method == "POST" or request.method == "GET":
AttributeError: module 'flask_openapi3.request' has no attribute 'method'
=============
Question: now the app is flask-openapi3 instead of simply flask, then
Thanks
Beta Was this translation helpful? Give feedback.
All reactions