import json

# 使用三引号将浏览器复制出来的requests headers参数赋值给一个变量
headers = """
Host: zhan.qq.com
Proxy-Connection: keep-alive
Content-Length: 799432
Pragma: no-cache
Cache-Control: no-cache
Origin: https://www.colorgg.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryuptjZg9xmsfWzngP
Accept: */*
Referer: https://www.colorgg.com
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Cookie: pgv_pvi=4342937600; RK=xFr4lrf07R; ptcz=a247c6170fb56cb4d5d41bf8461f11097a9be27bc7e7dc8b921254de9b1c924b;
""" # 去除参数头尾的空格并按换行符分割
headers = headers.strip().split('\n') # 使用字典生成式将参数切片重组,并去掉空格,处理带协议头中的://
headers = {x.split(':')[0].strip(): ("".join(x.split(':')[1:])).strip().replace('//', "://") for x in headers} # 使用json模块将字典转化成json格式打印出来
print(json.dumps(headers,indent=1))

使用python将请求的requests headers参数格式化方法的更多相关文章

  1. python 网络请求类库 requests 使用

    python 网络请求类库 requests 使用 requests是 为python封装的强大 REST 操作类库 githubhttps://github.com/kennethreitz/req ...

  2. java遍历http请求request的所有参数实现方法

    方法一: 通过程序遍历http请求的所有参数放到hashmap中,用的时候方便了. 如果参数值有中文,那么需要在程序中添加filter转码,或者在下面程序里,对paramValue转码 Map map ...

  3. Python利器一之requests

    Python利器一之requests 一.教程涉及开发语言.脚本.框架.数据库等内容 Python + requests 通过 pip 安装: pip install requests 通过 easy ...

  4. 【Python】 requests 各种参数请求的方式

    Python使用requests发送post请求 1.我们使用postman进行接口测试的时候,发现POST请求方式的编码有3种,具体的编码方式如下: A:application/x-www-form ...

  5. python非转基因HTTP请求库--Requests: 让 HTTP 服务人类

    快速上手 迫不及待了吗?本页内容为如何入门 Requests 提供了很好的指引.其假设你已经安装了 Requests.如果还没有,去安装一节看看吧. 首先,确认一下: Requests 已安装 Req ...

  6. Python+Post请求中涉及到多个参数data方法的应用

    进行post请求,Python提供了httplib.urllib2,同时也可以引用requests模块的一些方法.前几天做持续集成,运用requests写了一个post请求.代码如下: import ...

  7. requests.get() 的 headers 参数

    官方文档requests.get()方法的定义如下: 源码如下: 看到最后一行return,get方法最后是通过调用requests.request 方法实现的,其实在其它的请求方法如post,put ...

  8. Python爬虫【二】请求库requests

    一.requests的常用请求方式 #各种请求方式:常用的就是requests.get()和requests.post() >>> import requests >>& ...

  9. Python常见问题 - python3 使用requests发送HTTPS请求报certificate verify failed 错误

    当你使用 requests 发送HTTPS请求时 requests.get(url, parmas=parmas, headers=header, cookies=cookie) 出现了以下错误 HT ...

随机推荐

  1. ios中使用socket实现聊天

    [iOS]SocketRocket简单实现聊天室功能 https://www.jianshu.com/p/db34940f1135      CocoaAsyncSocket   https://gi ...

  2. laravel API

    /** * [api] * @author Foreach * @param string $method [请求方式] * @param string $url [地址] * @param arra ...

  3. SQL SERVER 2005还原差异备份、日志备份 2012-03-29 11:43

    其实要备份,还原最安全最有保障的是完全备份.但是完全备份肯定是需要更多的磁盘空间的开销.尤其是数据量比较大的.比如基数是500M,每天的增长量为10M,那么第一次完全备份是500M,第二次是510M, ...

  4. .net core 2.1控制台使用Quartz.net实现定时任务执行

    权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/qq_33435149/article/de ...

  5. spring boot 中 2.X 的跨域请求

    解决跨域: @Configuration @EnableAutoConfiguration public class ZooConfiguration { @Bean public FilterReg ...

  6. Python学习笔记009

    不换行 print("Hello,world!",end='')print("Hello,world!",end='')print("Hello,wo ...

  7. Ubuntu18.04-MySQL8.0-表名大小写敏感-远程连接

    1.卸载 停止服务 sudo service mysql stop 删除mysql服务 sudo apt-get remove mysql-server 删除其他组件 sudo apt-get aut ...

  8. Nodejs 开发 随手记

    console.log(Object.prototype.toString.call(Now.toString())); //类型判断

  9. Color Space 和 Color Range

    颜色有两个属性Color Range和Color Space 有关Color Space的解释可以看下面两个链接: https://www.jianshu.com/p/facdbab5ac20 htt ...

  10. SELinux永久关闭

    目录 SELinux永久关闭 参考 SELinux三种模式 永久关闭方法 SELinux永久关闭