程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何查看我的Python应用程序发送的整个HTTP请求?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何查看我的Python应用程序发送的整个HTTP请求??

开发过程中遇到如何查看我的Python应用程序发送的整个HTTP请求?的问题如何解决?下面主要结合日常开发的经验,给出你关于如何查看我的Python应用程序发送的整个HTTP请求?的解决方法建议,希望对你解决如何查看我的Python应用程序发送的整个HTTP请求?有所启发或帮助;

一种简单的方法:启用登录最新版本的请求(1.x及更高版本)。

请求用途http.clIEnt和logging模块配置到控制日志记录级别,如所描述这里。

示范 摘自链接文档的代码:

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')

示例输出

$ python requests-logging.py 
INFO:requests.packages.urllib3.connectionpool:Starting new httpS connection (1): httpbin.org
send: 'GET /headers http/1.1\r\nHost: httpbin.org\r\nAccept-EnCoding: gzip, deflate, compress\r\nAccept: */*\r\nUser-Agent: python-requests/1.2.0 cpython/2.7.3 linux/3.2.0-48-generic\r\n\r\n'
reply: 'http/1.1 200 OK\r\n'
header: Content-Type: application/Json
header: Date: Sat, 29 Jun 2013 11:19:34 GMT
header: Server: gunicorn/0.17.4
header: Content-Length: 226
header: Connection: keep-alive
DEBUG:requests.packages.urllib3.connectionpool:"GET /headers http/1.1" 200 226

解决方法

就我而言,我正在使用该requests库通过HTTPS调用PayPal的API。不幸的是,我从贝宝(PayPal)收到一个错误,贝宝(PayPal)支持人员无法弄清楚该错误是什么或由什么引起的。他们希望我“请提供整个请求,包括标头”。

我怎样才能做到这一点?

大佬总结

以上是大佬教程为你收集整理的如何查看我的Python应用程序发送的整个HTTP请求?全部内容,希望文章能够帮你解决如何查看我的Python应用程序发送的整个HTTP请求?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: