Use python for api testing, pythonapi
The original Article connection: http://blog.csdn.net/freewebsys/article/details/46228421 reproduced please indicate the source!
1. About requests
Requests is an http client library of python. It is designed to simplify http test writing.
Official Website:
Https://pypi.python.org/pypi/requests/
Http://docs.python-requests.org/en/latest/user/quickstart/#make-a-request
Github Project address
Https://github.com/kennethreitz/requests/
2. Development Environment
It is very convenient to build a development environment under mac.
sudo easy_install pipsudo pip install requests
Test: python command line
import requests>>> r = requests.get('https://api.github.com/user', auth=('user', 'pass'))>>> r.status_code200>>> r.headers['content-type']'application/json; charset=utf8'>>> r.encoding'utf-8'>>> r.textu'{"type":"User"...'>>> r.json(){u'private_gists': 419, u'total_private_repos': 77, ...}
Development Tool. Before using sublime, we found that an error occurred during running and did not recognize table characters.
IndentationError: unindent does not match any outer indentation level
The code is not found. I began to doubt my life.
The space difference between python code is really crazy. I began to miss the words with braces and semicolons.
To solve this problem, change the IDE tool directly. It is developed by IDA.
: Https://www.jetbrains.com/pycharm/download/
Download the Community version directly, because it is just a script, and it does not use a complicated framework.
The result is very good. The code in the direct format is as good as that in java, and debugging can be run. Right-click and run successfully.
3. test interface
Nothing is too complicated. simply use the requests framework.
#! /Usr/bin/python #-*-coding: UTF-8-*-################ python concise tutorial http://woodpecker.org.cn/abyteofpython_cn/chinese/ import requests # test Baidu def baidu_func (url ): headers = {} params = {} req = requests. post (url, headers = headers, params = params) print (req. text) if _ name _ = '_ main _': url = "http://www.baidu.com" baidu_func (url)
4. Summary
The original Article connection: http://blog.csdn.net/freewebsys/article/details/46228421 reproduced please indicate the source!
Testing is very important, especially for external interface vulnerabilities. It takes time to carefully test and analyze the code carefully.
Security is very important and it takes time to think about it.
Python is easy to learn. You can learn the syntax in an hour.
Python concise Tutorial:
Http://woodpecker.org.cn/abyteofpython_cn/chinese/
At the same time, penetration testing and many security scanning tools are also written in python. The PyCharm CE development tool is powerful enough to help you quickly learn python.
WxPython is a good choice for quick interface development.