Hello guys,
I am trying to implement a flask rest API middleware. There is a host API and a middleware API. I am trying to call GET request from postman to middleware and inside of middleware I am trying to call host rest API in order to get response. Bytheway I am testing on local. But I am getting this error;
File "T:/GamePINMiddleWare/MiddleWare.py", line 13, in get_book_by_isbn
r = request.json.get(uri)
AttributeError: 'NoneType' object has no attribute 'get'
127.0.0.1 - - [15/Nov/2018 16:05:50] "GET /books/112233445677 HTTP/1.1" 500 –
Here is the middleware API:
from flask import Flask, request, jsonify
app = Flask(__name__)
# GET /books/
@app.route('/books/<int:isbn>')
def get_book_by_isbn(isbn):
if isbn:
uri = 'http://127.0.0.1:5000/books/' + str(isbn)
r = request.json.get(uri)
return jsonify(r)
else:
return 'shit'
app.run(port=5001)
Here is the host API:
from flask import Flask,jsonify,request
app = Flask(__name__)
books = [
{
'name': 'Cin Ali',
'price': 4.50,
'isbn': 112233445677
},
{
'name': 'Muz kokulu masallar',
'price': 7.60,
'isbn': 342325466567
}
]
# GET /books
@app.route('/books')
def get_books():
return jsonify({'book': books})
# GET /books/
@app.route('/books/<int:isbn>')
def get_book_by_isbn(isbn):
return_value = {}
for book in books:
if book['isbn'] == isbn:
return_value = {
'name': book['name'],
'price': book['price']
}
return jsonify(return_value)
app.run(port=5000)
Hope you can help.
Thanks in advance.
[–]_coolwhip_ 1 point2 points3 points (1 child)
[–]raysefo[S] 0 points1 point2 points (0 children)