#!/usr/bin/env python
#coding:utf-8
import requests,urllib,urllib2,urllib3,urlparse
url = "http://xxx.com/index.php?Q=u=%OS%26%20"
print "original:",url
#print requests.get(url).content
print "-------------------"
url_parts = urlparse.urlparse(url)
print "splited:",url_parts.query
print "-------------------"
params = dict(urlparse.parse_qsl(url_parts.query,True))
print "parsed:","Q="+params['Q']
print "-------------------"
url_dealed = urlparse.urlunsplit((url_parts.scheme,url_parts.netloc\
,url_parts.path,urllib.urlencode(params)\
,url_parts.fragment))
print "unsplited(dealed_final):",url_dealed
print "-------------------"
#requests.get(url="http://xxx.com/index.php?Q=u=%OS%26%20").content
#requests.get(url="http://xxx.com/index.php",params).content
print "requests:","http://xxx.com/index.php?Q=u=%25OS%2526%2520"
#urllib.urlopen(url="http://xxx.com/index.php?Q=u=%OS%26%20").read()
print "urllib:","http://xxx.com/index.php?Q=u=%OS%26%20"
#urllib2.urlopen(url="http://xxx.com/index.php?Q=u=%OS%26%20").read()
print "urllib2:","http://xxx.com/index.php?Q=u=%OS%26%20"
#urllib3.ProxyManager('http://localhost:8888/').request("GET", "http://xxx.com/index.php?Q=u%3D%25OS%26+").data
print "urllib3:","http://xxx.com/index.php?Q=u=%OS%26%20"
#url_dealed = "http://xxx.com/index.php?Q=u%3D%25OS%26+"
#requests.get(url_dealed).content
#urllib3.ProxyManager('http://localhost:8888/').request("GET", url_dealed).data
#urllib2.urlopen(url_dealed).read()
#urllib.urlopen(url_dealed).read()
print "all requests dealed_final:","http://xxx.com/index.php?Q=u%3D%25OS%26+"
借号发个学习交流帖,求各路大神科普四个python库的默认编码行为差异:
今天测试个注入,把浏览器的url贴到requests参数里发包一直没得到预期响应,决定抓包diff一把,没想到真是requests做了手脚。
1. requests请求http://xxx.com/index.php?Q=u=%25OS%2526%2520会把Q值中的%都URL编码为%25。
2. requests请求经过分割-编码-组装处理后的http://xxx.com/index.php?Q=u%3D%25OS%26+保持原样。
3. urllib,urllib2,urllib3对1,2中的URL请求都保持原样。
说好的requests是封装的urllib3,为啥要改变这种默认行为?