不允许的方法对于显示错误的请求的URl,不允许使用该方法

时间:2018-11-19 09:58:25

标签: python mysql flask

以下代码尝试将json数据上传到MySQL数据库,但显示诸如“不允许使用方法所请求的URL不允许使用该方法”之类的错误。没有将json数据上传到MySQL数据库。请帮助我代码中的确切问题。我是使用烧瓶的新用户。运行代码后,我得到了上面的错误。

    from __future__ import print_function
    from flask import Flask, request, jsonify, render_template
    from werkzeug import secure_filename
    from flask_cors import CORS
    from random import randint
    try:
        import pymysql
        pymysql.install_as_MySQLdb()
    except ImportError:
        pass
    import MySQLdb
    import json
    a= [{"JD_Name": "Data Engineer","ID":10,"No_of_Position":5,"Skill_Sets":"Big Data, Python, Hadoop, MapReduce", "Created_Date":"2018-06-30","Received_profile":25,"Interview_completed":4,"Yet_to_schedule":10, 
    "Attachments":"https://s1.amazon.com/jd-upload/DataJD.docx"}]

    app = flask.Flask(__name__)
    CORS(app)
    app.config["DEBUG"] = True

    # do validation and checks before insert
    def validate_string(val):
        if val != None:
            if type(val) is int:
                #for x in val:
                #   print(x)
                return str(val).encode('utf-8')
            else:
                return val

  @app.route("/uploaddata", methods=['POST'])
def upload_file():
    db = MySQLdb.connect("localhost", "root", "Mysql1!","test")
    cur = db.cursor()
    for i, item in enumerate(a):
        JD_Name= validate_string(item.get("JD_Name", None))
        ID= validate_string(item.get("ID", None))
        No_of_Position= validate_string(item.get("No_of_Position", None))
        Skill_Sets= validate_string(item.get("Skill_Sets", None))
        Created_Date= validate_string(item.get("Created_Date", None))
        Received_profile= validate_string(item.get("Received_profile", None))
        Interview_completed= validate_string(item.get("Interview_completed", None))
        Yet_to_schedule= validate_string(item.get("Yet_to_schedule", None))
        Attachments= validate_string(item.get("Attachments", None))

    cursor.execute("INSERT INTO addjd1 (JD_Name, ID, No_of_Position, Skill_Sets, Created_Date, Received_profile, Interview_completed, Yet_to_schedule, Attachments) VALUES (%s,  %s,  %s,  %s,  %s,  %s,  %s,  %s,  %s)", (JD_Name, ID, No_of_Position, Skill_Sets, Created_Date, Received_profile, Interview_completed, Yet_to_schedule, Attachments))
    con.commit()
    con.close()
    return 'file uploaded successfully'

app.run()

0 个答案:

没有答案