Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

Passing an array in angular in python api-not working

I want to pass an array as a list in python api,but its working as expected.here is the code below of my input section of python api

here a is a string and b is list parameter.

tfidf_get_args = reqparse.RequestParser()

tfidf_get_args.add_argument("a", type=str, help="Enter Landing page url:",required=True)

tfidf_get_args.add_argument("b", type=str,action='append', help="Enter a list urls,separated by a comma.Hit enter when you finished:",required=True)

class tfidf(Resource):
    def post(self):
        my_list=[]
try:
            str_type = 'string format'
            array_type = ['1','2']
            c = request.values.get('a')
            d = request.values.get('b')
            if type(d) == type(str_type):
                print("is String")
                new_str = d.replace("[", "")
                new_str = new_str.replace("]", "")
                new_str = new_str.replace('"', "")
                my_list = new_str.split(",")
                print(my_list)
                print(type(my_list))
                print("======================================")
                my_list.insert(0,c)
                print(my_list)
                print("======================================")

            elif type(d) == type(array_type):
                print("is List")
                my_list=d
                print(my_list)
                print("======================================")
                my_list.insert(0,c)
                print(my_list)
                print("======================================")
            else:
                hhh="Invalid type input"

                return jsonify({"status": True,"Input":hhh})

        except:
            print("=====Error======")
            return jsonify({"status": False,"Input":"Error"})

my main objective is that taking one url from a and taking multiple urls form b and make a list of both.

my angular input response

a   "https://www.arkadium.com/free-online-games/"
b   […]
0   "http://games.disney.in/"
1   "https://www.king.com/games"
2   "https://www.bgames.com/"

Response

{ status: true, Input: "Invalid type input" }

as you can see its getting into else part.

how to solve this issue??


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...