Category : flask-restful

I am creating a RESTful API Python Lambda with flask, which needs to return a PDF. To return binary media from a Lambda it needs to be Base64 encoded, see here for AWS Docs Essentially, the return object must contain the attribute isBase64Encoded as shown: return { ‘headers’: { "Content-Type": "application/pdf" }, ‘statusCode’: 200, ‘body’: ..

Read more

I need response please . I create a one Chart . The Chart with the same name as the Chart we made create should not be create like duplicates are not allowed validate slice_name unique # ChartDAO.validate_update_slice_name_uniqueness name = data["slice_name"] print("================>", name) if not ChartDAO.validate_create_slice_name_uniqueness(name): return json_error_response( __( "This slice Name was same name." "slice ..

Read more

I am trying to learn how to use RESTapi, so i am in a beginner level. the code in Pycharm: enter code herefrom flask import Flask from flask_restful import Resource, Api, reqparse app = Flask(__name__) api = Api(app) STUDENTS = {‘1’: {‘name’: ‘Mark’, ‘age’: 23, ‘spec’: ‘math’}, ‘2’: {‘name’: ‘Jane’, ‘age’: 20, ‘spec’: ‘biology’}, ‘3’: ..

Read more

This is my code, import requests url = ‘https://api’ files=[(‘file’,(‘image.png’,open(‘/C:/Users/Swarnitha/Downloads/image.png’,’rb’),’image/png’))] #files = {"file":open(‘/C:/Users/Swarnitha/Downloads/image.png’,’rb’)} response = requests.post(url, files=files) In windows I am sending the path of the file like this. I am getting error as Traceback (most recent call last): File "test.py", line 66, in (‘file’,(‘image.png’,open(‘/C:/Users/Swarnitha/Downloads/image.png’,’rb’),’image/png’)) FileNotFoundError: [Errno 2] No such file or directory: ‘/C:/Users/Swarnitha/Downloads/image.png’ Usually ..

Read more

I have a class for users which then has a method to save data to the database. class User(db.Model, ExtraMixin): first_name = db.Column(db.String(50), nullable=False) last_name = db.Column(db.String(50), nullable=False) other_names = db.Column(db.String(100), nullable=True) phone_number = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), index=True, unique=True, nullable=False) password = db.Column(db.String(200), nullable=False) user_type_id = db.Column(db.Integer, db.ForeignKey(‘user_type.id’)) vendor_id = db.Column(db.Integer, db.ForeignKey(‘vendor.id’), ..

Read more

Here is my code: @app.route(‘/students’) def students(): list = Student.query.all() print(type(list)) #class:list studentList2 ={} for student in list: studentList2= ({‘id’:student.id,’title’:student.title,’email’:student.email}) print(studentList2) # the loop can show student1,2,3 etc. print(type(studentList2)) #class:dict print(studentList2) # Only show the last student return jsonify(studentList2) The loop can show student1,2,3 etc. But I don’t know how to return in JSON. Source: ..

Read more