Generate QRcode using Python

Generate QRcode using Python
Step 1: Download and Install Python
Step 2: Open CMD prompt and run the following command to install flask and pyqrcode module
>> pip install flask
>> pip install pyqrcode
Step 3: Open the new text document and place the following code
import io
from flask import Flask, send_file, request
import pyqrcode
app=Flask(__name__)
@app.route(‘/qrcode’, methods=[‘GET’])
def search_data():
    query = request.args.get(‘query’, ”)
    qr = pyqrcode.create(query)
    qr.png(query+’.png’, scale=3)
    with open(query+’.png’, ‘rb’) as bites:
        return send_file(
                     io.BytesIO(bites.read()),
                     attachment_filename=query+’.png’,
                     mimetype=’image/png’
               )
if __name__ == “__main__”:
    app.run(debug=True)  
Step 4: Save the file in .py format. (e.g. file_nm.py)
Step 5: Deploy this python web app in Restful web service.
  • January 17, 2019 | 19 views
  • Comments