> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/python/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/python/chapter1notes-from-research/chapter-5-web-crawler/request.md).

# 4.2.requests

* 1.requests module
  * methods
    * reuests.get
    * reuests.post
    * reuests.put
    * reuests.delete
  * HTTP狀態碼:
    * <https://zh.wikipedia.org/wiki/HTTP%E7%8A%B6%E6%80%81%E7%A0%81>
  * REST API
    * <https://zh.wikipedia.org/wiki/REST>
* 2.Install **request** module
  * <http://docs.python-requests.org/zh_CN/latest/user/install.html#install>

    ```
      git clone git://github.com/kennethreitz/requests.git
      python setup.py install
    ```
* 3.GET
  * 1.發送請求
    * 響應內容, JSON響應內容, 狀態碼

      ![](https://github.com/jenhsuan/python/tree/8fc9c0b8df4ccd709d3078c2d8842af0932de09d/assets/螢幕快照%202017-03-18%20下午10.57.04.png)
  * 2.在header中加入參數

    ```
      import requests
      url = 'http://10.144.5.183/api/v1/devices'
      t = '$2a$10$RqOyphofSoIOwO8mbhEXfOYIX7ZkjrFUyrEPsJ4yzRzvRq/u'
      h = {'api-token': t}
      r = requests.get(url, headers=h)
      print r.text
    ```
