zoukankan      html  css  js  c++  java
  • Requests杂谈

    请求  1 get请求   r = requests.get('https://api.github.com/events')  r = requests.get(url, headers=headers)
      2 post请求  r = requests.post('http://httpbin.org/post', data = {'key':'value'})
      3传参    
    >>> payload = {'key1': 'value1', 'key2': 'value2'}
            >>> r = requests.get("http://httpbin.org/get", params=payload)
    响应  1
    r.text 为str  r.content二进制响应 为bite,用 r.content.decode()编码     r.raw 为原始响应内容
      Requests 中也有一个内置的 JSON 解码器,助你处理 JSON 数据:如果 JSON 解码失败, r.json() 就会抛出一个异常。例如,响应内容是 401 (Unauthorized),尝试访问 r.json() 将会抛出 ValueError: No JSON object could be decoded 异常
      通常,你想要发送一些编码为表单形式的数据——非常像一个 HTML 表单。要实现这个,只需简单地传递一个字典给 data 参数。你的数据字典在发出请求时会自动编码为表单形式:

  • 相关阅读:
    面试
    vue axios 应用
    3D全景之ThreeJs
    css垂直居中
    事件处理过程中遇到的问题
    文字溢出
    jquery: 偏移量计算
    jquery: sand picture
    jquery: update carousel logic & animate
    jquery: carousel arrow click
  • 原文地址:https://www.cnblogs.com/ithairy/p/9220764.html
Copyright © 2011-2022 走看看