1. 程式人生 > >接口_requests_基於python

接口_requests_基於python

ini direct path auth tsd clas chardet method .py

HTTP request python官方文檔:http://cn.python-requests.org/zh_CN/latest/

基於環境,需要安裝requests 模塊,安裝方法 pip install requests
想學習requests,就通過help吧

import requests
help(requests)

返回結果如下:

C:\Python27\python.exe E:/test/interface/g_3.py
Help on package requests:

NAME
    requests

FILE
    c:\python27\lib\site-packages\requests\__init__
.py DESCRIPTION Requests HTTP Library ~~~~~~~~~~~~~~~~~~~~~ Requests is an HTTP library, written in Python, for human beings. Basic GET usage: >>> import requests >>> r = requests.get(https://www.python.org) >>> r.status_code
200 >>> Python is a programming language in r.content True ... or POST: >>> payload = dict(key1=value1, key2=value2) >>> r = requests.post(http://httpbin.org/post, data=payload) >>> print(r.text) { ...
"form": { "key2": "value2", "key1": "value1" }, ... } The other HTTP methods are supported - see `requests.api`. Full documentation is at <http://python-requests.org>. :copyright: (c) 2017 by Kenneth Reitz. :license: Apache 2.0, see LICENSE for more details. PACKAGE CONTENTS __version__ _internal_utils adapters api auth certs compat cookies exceptions help hooks models packages sessions status_codes structures utils FUNCTIONS check_compatibility(urllib3_version, chardet_version) DATA __author__ = Kenneth Reitz __author_email__ = [email protected] __build__ = 137220 __cake__ = u\u2728 \U0001f370 \u2728 __copyright__ = Copyright 2017 Kenneth Reitz __description__ = Python HTTP for Humans. __license__ = Apache 2.0 __title__ = requests __url__ = http://python-requests.org __version__ = 2.18.4 codes = <lookup status_codes> VERSION 2.18.4 AUTHOR Kenneth Reitz Process finished with exit code 0

獲取requests所有的方法和類,就使用dir吧

import requests
print dir(requests)

返回如下:

[ConnectTimeout, ConnectionError, DependencyWarning, FileModeWarning, HTTPError, NullHandler, PreparedRequest, ReadTimeout, Request, RequestException, RequestsDependencyWarning, Response, Session, Timeout, TooManyRedirects, URLRequired, __author__, __author_email__, __build__, __builtins__, __cake__, __copyright__, __description__, __doc__, __file__, __license__, __name__, __package__, __path__, __title__, __url__, __version__, _internal_utils, adapters, api, auth, certs, chardet, check_compatibility, codes, compat, cookies, delete, exceptions, get, head, hooks, logging, models, options, packages, patch, post, put, request, session, sessions, status_codes, structures, urllib3, utils, warnings]

接口_requests_基於python