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 参数。你的数据字典在发出请求时会自动编码为表单形式:

  • 相关阅读:
    c#+linux+mono+Redis集群(解决无法连接Redis的问题)
    实验楼----奇妙的音乐
    实验楼----PHP大法
    实验楼----PHP代码审计(sha1、md5)
    实验楼----变异凯撒
    storm安装
    storm问题汇总
    windows下linux子系统安装
    mongoDB学习记录
    excel vba 不可查看
  • 原文地址:https://www.cnblogs.com/ithairy/p/9220764.html
Copyright © 2011-2022 走看看