python request重定向踩坑记录

python request重定向踩坑记录

写POC的时候,遇到一个问题,用burp验证成功,但成python脚本却一直验证失败,感觉写的代码没问题,多次尝试无果后,经过大师傅提示,看一下发出的包和burp发出的包有什么区别,就去网上查python如何获取完整的HTTP请求,找到了如下方法:
方法来源:https://stackoverflow.com/questions/10588644/how-can-i-see-the-entire-http-request-thats-being-sent-by-my-python-application

import requests
import logging

# These two lines enable debugging at httplib level (requests->urllib3->http.client)
# You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
# The only thing missing will be the response.body which is not logged.
try:
    import http.client as http_client
except ImportError:
    # Python 2
    import httplib as http_client
http_client.HTTPConnection.debuglevel = 1

# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

requests.get('https://httpbin.org/headers')

使用代码后发现,我发出的post请求,先是返回了一个302的响应,正是我想要的,然后它又重定向到了另一个url上,然后返回了200的响应,怪不得一直验证失败!
在这里插入图片描述
然后查了一下如何禁止重定向

使用方法:allow_redirects=False直接加到requests里面
在这里插入图片描述
然后就验证成功了,返回了302状态码的包
在这里插入图片描述
虽然在这上面花费了不少时间,但算是学到了一招,也不亏。哈哈。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值