Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of flask and curl

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will show you what the usage of flask and curl is. The knowledge points in the article are introduced in great detail. Friends who feel helpful can browse the content of the article with the editor, hoping to help more friends who want to solve this problem to find the answer to the problem. Let's learn more about "what is the use of flask and curl" with the editor.

Basically familiar with the use of flask and curl, so write a program:

_ _ author__ = 'hochikong'from flask import Flask,requestfrom flask.ext.restful import Resource,Api,reqparseapp = Flask (_ _ name__) api = Api (app) todos = {} parser = reqparse.RequestParser () parser.add_argument (' name',type=str,help='get the name') class TodoSimple (Resource): def get (self,todo_id): return {todo_id: todo _ id]} def put (self Todo_id): Todos [Todo _ id] = request.form ['data'] return {todo_id: Todo [Todo _ id]} 201class GetName (Resource): def post (self): args = parser.parse_args () name = {} name ['ac'] = args [' name'] return name # args = parser.parse_args () # name = args ['name'] # return nameapi.add_resource (TodoSimple,'/') api.add_resource (GetName '/ getname') if _ _ name__ = =' _ main__': app.run ()

Pay attention to the comments in the code. When using reqparse, if you write according to the comments, the following questions will appear:

Hochikong@hochikong-P41T-D3:~$ curl http://localhost:5000/getname-d "name=hochikong"-X POST-v * Hostname was NOT found in DNS cache* Trying 127.0.0.1. * Connected to localhost (127.0.0.1) port 5000 (# 0) > POST / getname HTTP/1.1 > User-Agent: curl/7.35.0 > Host: localhost:5000 > Accept: * / * > Content-Length: 14 > Content-Type: application/x-www-form-urlencoded > * upload completely sent off: 14 out of 14 bytes* HTTP 1.0 Assume close after body < HTTP/1.0 200 OK < Content-Type: application/json < Content-Length: 11 < Server: Werkzeug/0.10.1 Python/2.7.6 < Date: Sat, 21 Mar 2015 15:00:18 GMT < * Closing connection 0

Although it is 200, no data is returned.

I think the output of args ['name'] is indeed a string, but the response of flask-RESTful should be:

Content-Type: application/json

There is no way to format a single string in json format.

But once put in the python dictionary, the result of return is a legitimate json output.

I guessed wow:)

Thank you for your reading. This is the whole content of "what is the use of flask and curl?" Let's get started. I believe that the editor will certainly bring you better quality articles. Thank you for your support to the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report