request实例1:

import requests
payload = {'key1':'value','key2':'value2'}
url = "http://httpbin.org/get"
headers = {'content-type': 'application/json'}
res = requests.get(url,params=payload,headers=headers)
res.encoding="utf-8"
print("1.url: ")
print(res.url)
print("2.text: ")
print(res.text)
print("3.json: ")
print(res.json())
print("4.status_code: ")
print(res.status_code)

结果:

1.url:
http://httpbin.org/get?key1=value&key2=value2
2.text:
{
"args": {
"key1": "value",
"key2": "value2"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.18.4"
},
"origin": "117.25.182.2",
"url": "http://httpbin.org/get?key1=value&key2=value2"
} 3.json:
{'args': {'key1': 'value', 'key2': 'value2'}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Content-Type': 'application/json', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.18.4'}, 'origin': '117.25.182.2', 'url': 'http://httpbin.org/get?key1=value&key2=value2'}
4.status_code:
200

request实例2:

import requests
payload = {'key1':'value1','key2':'value2'}
url = "http://httpbin.org/post"
headers = {'content-type': 'application/json'}
res =requests.post(url,data=payload,headers=headers)
print("1.url: ")
print(res.url)
print("2.text: ")
print(res.text)
print("3.json: ")
print(res.json())
print("4.status_code: ")
print(res.status_code)

  结果:

1.url:
http://httpbin.org/post
2.text:
{
"args": {},
"data": "key1=value1&key2=value2",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Content-Length": "23",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.18.4"
},
"json": null,
"origin": "117.25.182.2",
"url": "http://httpbin.org/post"
} 3.json:
{'args': {}, 'data': 'key1=value1&key2=value2', 'files': {}, 'form': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Content-Length': '23', 'Content-Type': 'application/json', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.18.4'}, 'json': None, 'origin': '117.25.182.2', 'url': 'http://httpbin.org/post'}
4.status_code:
200

 request实例3: 

import requests
url = 'http://httpbin.org/cookies'
cookies = dict(cookies_are='working')
r = requests.get(url, cookies=cookies)
print("1.url: ")
print(res.url)
print("2.text: ")
print(res.text)
print("3.json: ")
print(res.json())
print("4.status_code: ")
print(res.status_code)

  

结果:

1.url:
http://httpbin.org/post
2.text:
{
"args": {},
"data": "key1=value1&key2=value2",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Content-Length": "23",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.18.4"
},
"json": null,
"origin": "117.25.182.2",
"url": "http://httpbin.org/post"
} 3.json:
{'args': {}, 'data': 'key1=value1&key2=value2', 'files': {}, 'form': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Content-Length': '23', 'Content-Type': 'application/json', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.18.4'}, 'json': None, 'origin': '117.25.182.2', 'url': 'http://httpbin.org/post'}
4.status_code:
200

  

python3.6的request的更多相关文章

  1. python3.6 urllib.request库实现简单的网络爬虫、下载图片

    #更新日志:#0418 爬取页面商品URL#0421 更新 添加爬取下载页面图片功能#0423 更新 添加发送邮件功能# 优化 爬虫异常处理.错误页面及空页面处理# 优化 爬虫关键字黑名单.白名单,提 ...

  2. python3 spider [ urllib.request ]

    # # 导入urllib库的urlopen函数 # from urllib.request import urlopen # # 发出请求,获取html # html = urlopen(" ...

  3. python3中urllib库的request模块详解

    刚刚接触爬虫,基础的东西得时时回顾才行,这么全面的帖子无论如何也得厚着脸皮转过来啊! 原帖地址:https://www.2cto.com/kf/201801/714859.html 什么是 Urlli ...

  4. Python3使用request/urllib库重定向问题

    禁止自动重定向 python3的urllib.request模块发http请求的时候,如果服务器响应30x会自动跟随重定向,返回的结果是重定向后的最终结果而不是30x的响应结果. request是靠H ...

  5. python3下urlopen解析中文url编码错误

    这是在ipython下测试的结果: In [24]: x Out[24]: 'http://127.0.0.1:8000/xxx/?id=a45ex0bad3c9&game=五子棋' In [ ...

  6. python3 抓取网页资源的 N 种方法

    1. 最简单 import urllib.request response = urllib.request.urlopen('http://python.org/') html = response ...

  7. Python3中urllib详细使用方法(header,代理,超时,认证,异常处理)

    urllib是python的一个获取url(Uniform Resource Locators,统一资源定址器)了,我们可以利用它来抓取远程的数据进行保存哦,下面整理了一些关于urllib使用中的一些 ...

  8. Python3中urllib详细使用方法(header,代理,超时,认证,异常处理) 转

    urllib是python的一个获取url(Uniform Resource Locators,统一资源定址器)了,我们可以利用它来抓取远程的数据进行保存哦,下面整理了一些关于urllib使用中的一些 ...

  9. urllib库详解 --Python3

    相关:urllib是python内置的http请求库,本文介绍urllib三个模块:请求模块urllib.request.异常处理模块urllib.error.url解析模块urllib.parse. ...

随机推荐

  1. [C#] == VS Equals

    声明:本篇博客翻译自:https://www.codeproject.com/Articles/1111680/equalsequals-VS-Equals-in-Csharp 由于水平(技术水平+英 ...

  2. 在sublime text中添加JavaScript的build-system

    -step 1: 下载安装node.js, 并添加到path变量中. -step 2: 在sublime text中新建一个build-system. tools --> build-syste ...

  3. Shell编程-03-Shell中的特殊变量和扩展变量

    目录 特殊变量 变量扩展 特殊变量     在Shell中的特殊变量主要分别两种位置参数变量.状态变量两种. 位置参数变量     Shell中的位置参数变量主要是指$0.$1.$#等,主要用于从命令 ...

  4. ETL的测试

    二.ETL测试过程: 在独立验证与确认下,与任何其他测试一样,ETL也经历同样的阶段. 1)业务和需求分析并验证. 2)测试方案编写 3)从所有可用的输入条件来设计测试用例和测试场景进行测试 4)执行 ...

  5. Win 8下Rime输入法无法同步的临时解决方法

    意外发现了Rime输入法(OS X上叫鼠须管'Squirrel',windows上叫小狼毫'Weasel',linux上叫中州韵'ibus-rime',连名字都起的这么牛逼),真是神器啊,流畅的速度, ...

  6. 疑难杂症--SQL SERVER 18056的错误

    朋友遇到一个很棘手的问题,查看服务器日志,报以下错误: ::,spid296,未知,错误: ,严重性: ,状态: . ::,spid495,未知, The client was unable < ...

  7. 查找 SQL SERVER 所有表记录数

    -- 所有表的记录数 SELECT a.name, b.rowsFROM sysobjects AS a INNER JOIN sysindexes AS b ON a.id = b.idWHERE ...

  8. 10-11Linux用户管理规则及用户管理函数

    用户管理: useradd, userdel, usermod, passwd, chsh, chfn, finger, id, chage 组管理: groupadd, groupdel, grou ...

  9. sqlserver数据库存储汉字出现?

    问题:有些相对复杂的汉字在数据库里会变成? 解决办法:原来数据类型是varchar,将数据类型修改为nvarchar

  10. ASP.NET Core IdentityServer4 新手上路

    OAuth2.0资料 今天看到一篇博主写了该系列文章,贴图和过程都比较详细,俗话说实践是检验真理的唯一标准(如果是按照参考文章复制粘贴,应该不会出现踩坑,但是我喜欢自己手动敲一遍),发现几个坑,因而总 ...