flask web 开发 P168
(venv) C:\Users\Geek Lee\flasky>http --json --auth 123456789@qq.com:password GET \
http: error: ConnectionError: HTTPConnectionPool(host='%5C', port=80): Max retries exceeded with url: / (Caused by <class'socket.gaierror'>: [Errno 11004] getaddrinfo failed)
C:\Users\Geek Lee\flasky>venv\Scripts\activate
(venv) C:\Users\Geek Lee\flasky>python manage.py runserver
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
127.0.0.1 - - [05/Sep/2016 20:52:11] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [05/Sep/2016 20:53:09] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [05/Sep/2016 20:54:34] "GET /api/v1.0/posts HTTP/1.1" 301 -
127.0.0.1 - - [05/Sep/2016 20:55:38] "GET /api/v1.0/posts/ HTTP/1.1" 200 -
127.0.0.1 - - [05/Sep/2016 20:56:05] "GET /api/v1.0/posts/ HTTP/1.1" 200 -
(venv) $:>http --json --auth 123456789@qq.com:password GET http://127.0.0.1:5000/api/v1.0/posts/
结果
(venv) $:>http --json --auth 123456789@qq.com:password GET http://127.0.0.1:5000/api/v1.0/posts/
HTTP/1.0 200 OK
Content-Length: 8456
Content-Type: application/json
Date: Mon, 05 Sep 2016 12:56:05 GMT
Server: Werkzeug/0.10.4 Python/3.4.3
{
"count": 107,
"next": "http://127.0.0.1:5000/api/v1.0/posts/?page=2",
"posts": [
{
"author": "http://127.0.0.1:5000/api/v1.0/users/4",
"body": "sss",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/1/comments/",
"timestamp": "Fri, 02 Sep 2016 02:32:52 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/1"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/4",
"body": "fsdfsdfs ",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/2/comments/",
"timestamp": "Fri, 02 Sep 2016 02:32:56 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/2"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/4",
"body": "sdfsdfsfs",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/3/comments/",
"timestamp": "Fri, 02 Sep 2016 02:32:59 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/3"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/4",
"body": "fsdfsfsafsfa",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/4/comments/",
"timestamp": "Fri, 02 Sep 2016 02:33:03 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/4"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/4",
"body": "为什么?",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/5/comments/",
"timestamp": "Fri, 02 Sep 2016 02:51:08 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/5"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/7",
"body": "Etiam vel augue.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/6/comments/",
"timestamp": "Wed, 24 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/6"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/39",
"body": "Cras in purus eu magna vulputate luctus. Suspendisse potent
i. In quis justo. Morbi vestibulum, velit id pretium iaculis, diam erat fermentu
m justo, nec condimentum neque sapien placerat ante. Etiam vel augue.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/7/comments/",
"timestamp": "Fri, 19 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/7"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/52",
"body": "Integer ac neque. Vestibulum rutrum rutrum neque. Aenean au
ctor gravida sem. Quisque ut erat.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/8/comments/",
"timestamp": "Mon, 22 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/8"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/3",
"body": "Donec posuere metus vitae ipsum.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/9/comments/",
"timestamp": "Sat, 27 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/9"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/80",
"body": "Sed ante. Pellentesque ultrices mattis odio.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/10/comments/",
"timestamp": "Sun, 14 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/10"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/58",
"body": "Nulla ac enim. Vestibulum ante ipsum primis in faucibus orc
i luctus et ultrices posuere cubilia Curae; Donec pharetra, magna vestibulum ali
quet ultrices, erat tortor sollicitudin mi, sit amet lobortis sapien sapien non
mi.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/11/comments/",
"timestamp": "Wed, 17 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/11"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/4",
"body": "Vestibulum rutrum rutrum neque. Donec vitae nisi. Fusce con
gue, diam id ornare imperdiet, sapien urna pretium nisl, ut volutpat sapien arcu
sed augue. Integer aliquet, massa id lobortis convallis, tortor risus dapibus a
ugue, vel accumsan tellus nisi eu orci.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/12/comments/",
"timestamp": "Sat, 20 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/12"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/43",
"body": "Praesent blandit lacinia erat. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Donec posuere metus vitae ipsum. In hac habitasse
platea dictumst.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/13/comments/",
"timestamp": "Wed, 17 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/13"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/63",
"body": "Nam tristique tortor eu pede. Etiam justo. Vestibulum ante
ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla da
pibus dolor vel est. Nulla tempus. Pellentesque ultrices mattis odio.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/14/comments/",
"timestamp": "Sat, 27 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/14"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/83",
"body": "Vivamus metus arcu, adipiscing molestie, hendrerit at, vulp
utate vitae, nisl. Integer pede justo, lacinia eget, tincidunt eget, tempus vel,
pede. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere
cubilia Curae; Mauris viverra diam vitae quam.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/15/comments/",
"timestamp": "Sat, 13 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/15"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/82",
"body": "Quisque erat eros, viverra eget, congue eget, semper rutrum
, nulla.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/16/comments/",
"timestamp": "Tue, 23 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/16"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/48",
"body": "Nulla ac enim.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/17/comments/",
"timestamp": "Fri, 19 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/17"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/13",
"body": "Nunc nisl. Cras non velit nec nisi vulputate nonummy. Nulla
neque libero, convallis eget, eleifend luctus, ultricies eu, nibh. Cras mi pede
, malesuada in, imperdiet et, commodo vulputate, justo.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/18/comments/",
"timestamp": "Sun, 28 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/18"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/75",
"body": "Nulla nisl.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/19/comments/",
"timestamp": "Thu, 01 Sep 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/19"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/46",
"body": "Donec semper sapien a libero. Vestibulum ante ipsum primis
in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris viverra diam v
itae quam.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/20/comments/",
"timestamp": "Sun, 28 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/20"
}
],
"prev": null
}
匿名用户
(venv) C:\Users\Geek Lee\flasky>http --json --auth : GET http://127.0.0.1:5000/a
pi/v1.0/posts/
HTTP/1.0 200 OK
Content-Length: 8456
Content-Type: application/json
Date: Mon, 05 Sep 2016 14:17:26 GMT
Server: Werkzeug/0.10.4 Python/3.4.3
{
"count": 107,
"next": "http://127.0.0.1:5000/api/v1.0/posts/?page=2",
"posts": [
{
"author": "http://127.0.0.1:5000/api/v1.0/users/4",
"body": "sss",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/1/comments/",
"timestamp": "Fri, 02 Sep 2016 02:32:52 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/1"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/4",
"body": "fsdfsdfs ",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/2/comments/",
"timestamp": "Fri, 02 Sep 2016 02:32:56 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/2"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/4",
"body": "sdfsdfsfs",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/3/comments/",
"timestamp": "Fri, 02 Sep 2016 02:32:59 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/3"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/4",
"body": "fsdfsfsafsfa",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/4/comments/",
"timestamp": "Fri, 02 Sep 2016 02:33:03 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/4"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/4",
"body": "为什么?",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/5/comments/",
"timestamp": "Fri, 02 Sep 2016 02:51:08 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/5"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/7",
"body": "Etiam vel augue.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/6/comments/",
"timestamp": "Wed, 24 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/6"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/39",
"body": "Cras in purus eu magna vulputate luctus. Suspendisse potent
i. In quis justo. Morbi vestibulum, velit id pretium iaculis, diam erat fermentu
m justo, nec condimentum neque sapien placerat ante. Etiam vel augue.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/7/comments/",
"timestamp": "Fri, 19 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/7"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/52",
"body": "Integer ac neque. Vestibulum rutrum rutrum neque. Aenean au
ctor gravida sem. Quisque ut erat.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/8/comments/",
"timestamp": "Mon, 22 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/8"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/3",
"body": "Donec posuere metus vitae ipsum.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/9/comments/",
"timestamp": "Sat, 27 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/9"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/80",
"body": "Sed ante. Pellentesque ultrices mattis odio.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/10/comments/",
"timestamp": "Sun, 14 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/10"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/58",
"body": "Nulla ac enim. Vestibulum ante ipsum primis in faucibus orc
i luctus et ultrices posuere cubilia Curae; Donec pharetra, magna vestibulum ali
quet ultrices, erat tortor sollicitudin mi, sit amet lobortis sapien sapien non
mi.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/11/comments/",
"timestamp": "Wed, 17 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/11"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/4",
"body": "Vestibulum rutrum rutrum neque. Donec vitae nisi. Fusce con
gue, diam id ornare imperdiet, sapien urna pretium nisl, ut volutpat sapien arcu
sed augue. Integer aliquet, massa id lobortis convallis, tortor risus dapibus a
ugue, vel accumsan tellus nisi eu orci.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/12/comments/",
"timestamp": "Sat, 20 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/12"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/43",
"body": "Praesent blandit lacinia erat. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Donec posuere metus vitae ipsum. In hac habitasse
platea dictumst.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/13/comments/",
"timestamp": "Wed, 17 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/13"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/63",
"body": "Nam tristique tortor eu pede. Etiam justo. Vestibulum ante
ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla da
pibus dolor vel est. Nulla tempus. Pellentesque ultrices mattis odio.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/14/comments/",
"timestamp": "Sat, 27 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/14"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/83",
"body": "Vivamus metus arcu, adipiscing molestie, hendrerit at, vulp
utate vitae, nisl. Integer pede justo, lacinia eget, tincidunt eget, tempus vel,
pede. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere
cubilia Curae; Mauris viverra diam vitae quam.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/15/comments/",
"timestamp": "Sat, 13 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/15"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/82",
"body": "Quisque erat eros, viverra eget, congue eget, semper rutrum
, nulla.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/16/comments/",
"timestamp": "Tue, 23 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/16"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/48",
"body": "Nulla ac enim.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/17/comments/",
"timestamp": "Fri, 19 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/17"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/13",
"body": "Nunc nisl. Cras non velit nec nisi vulputate nonummy. Nulla
neque libero, convallis eget, eleifend luctus, ultricies eu, nibh. Cras mi pede
, malesuada in, imperdiet et, commodo vulputate, justo.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/18/comments/",
"timestamp": "Sun, 28 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/18"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/75",
"body": "Nulla nisl.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/19/comments/",
"timestamp": "Thu, 01 Sep 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/19"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/46",
"body": "Donec semper sapien a libero. Vestibulum ante ipsum primis
in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris viverra diam v
itae quam.",
"body_html": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/20/comments/",
"timestamp": "Sun, 28 Aug 2016 00:00:00 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/20"
}
],
"prev": null
}
发送post请求以添加一篇新博客文章(两次输入,第一次错误,第二次正确,更改了body部分)
(venv) C:\Users\Geek Lee\flasky>http --auth 123456789@qq.com:password --json
POST http://127.0.0.1:5000/api/v1.0/posts/ "body = i add a post from the cmd."
HTTP/1.0 400 BAD REQUEST
Content-Length: 70
Content-Type: application/json
Date: Mon, 05 Sep 2016 14:39:47 GMT
Server: Werkzeug/0.10.4 Python/3.4.3
{
"error": "bad request",
"message": "post does not have a body"
}
(venv) C:\Users\Geek Lee\flasky>http --auth 123456789@qq.com:password --json
POST http://127.0.0.1:5000/api/v1.0/posts/ "body=I'm adding a post from the *co
mmand line*."
HTTP/1.0 201 CREATED
Content-Length: 378
Content-Type: application/json
Date: Mon, 05 Sep 2016 14:41:37 GMT
Location: http://127.0.0.1:5000/api/v1.0/posts/108
Server: Werkzeug/0.10.4 Python/3.4.3
{
"author": "http://127.0.0.1:5000/api/v1.0/users/4",
"body": "I'm adding a post from the *command line*.",
"body_html": "I'm adding a post from the command line.
",
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/108/comments/",
"timestamp": "Mon, 05 Sep 2016 14:41:37 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/108"
}
要想使用认证令牌,可向/api/v1.0/token发送请求
(venv)$ http --json --auth 123456789@qq.com:password GET http://127.0.0.1:5000/api/v1.0/token
HTTP/1.0 200 OK
Content-Length: 161
Content-Type: application/json
Date: Mon, 05 Sep 2016 14:22:47 GMT
Server: Werkzeug/0.10.4 Python/3.4.3
{
"expiration": 3600,
"token": "eyJpYXQiOjE0NzMwODUzNjcsImV4cCI6MTQ3MzA4ODk2NywiYWxnIjoiSFMyNTYifQ
.eyJpZCI6NH0.0tYKiDHowOF4uPcyVHx70faNCSNjOAil7qdMCTs_jcQ"
}