【问题标题】:python requests response locationpython请求响应位置
【发布时间】:2016-12-19 22:38:16
【问题描述】:

我正在尝试找到一种使用 python 请求获取响应位置的方法。当我使用 fiddler 或使用 python 请求时,返回的标头不包括它来自的位置。但是在我的浏览器中查看相同的请求,它会显示响应位置。无论如何这样做? 谢谢

【问题讨论】:

    标签: python python-requests fiddler


    【解决方案1】:

    这可以通过请求来完成;昨天必须弄清楚。

    r.headers['location']
    

    一般来说,print(yaml.dump(r)) 会显示完整的回复。

    • python 3.7 中的请求 v2.19.1

    【讨论】:

      【解决方案2】:

      这是一个使用urllib2 的示例,但我认为你不能使用requests 来做到这一点:

      >>> urllib2.urlopen('http://google.com').info().__dict__
      {'fp': None, 'status': '', 'startofbody': None, 'startofheaders': None, 'subtype': 'html', 'type': 'text/html', 'maintype': 'text', 'headers': ['Date: Mon, 19 Dec 2016 23:11:59 GMT\r\n', 'Expires: -1\r\n', 'Cache-Control: private, max-age=0\r\n', 'Content-Type: text/html; charset=ISO-8859-1\r\n', 'P3P: CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."\r\n', 'Server: gws\r\n', 'X-XSS-Protection: 1; mode=block\r\n', 'X-Frame-Options: SAMEORIGIN\r\n', 'Set-Cookie: NID=93=TKYj49Z3JkIbdrSKS3TgOIKLualPZ--E7dYEXg0S4lYvveiaGLAWjXWpy6xNrutXuTkEkaUH5u1K8Gq8jbWaG5uDENsg3deeSOWNFqCM-YCIe_TZMeu7eUj3PW5__Yzid7gpeUUiEiNa0Q; expires=Tue, 20-Jun-2017 23:11:59 GMT; path=/; domain=.google.com; HttpOnly\r\n', 'Accept-Ranges: none\r\n', 'Vary: Accept-Encoding\r\n', 'Connection: close\r\n'], 'dict': {'x-xss-protection': '1; mode=block', 'set-cookie': 'NID=93=TKYj49Z3JkIbdrSKS3TgOIKLualPZ--E7dYEXg0S4lYvveiaGLAWjXWpy6xNrutXuTkEkaUH5u1K8Gq8jbWaG5uDENsg3deeSOWNFqCM-YCIe_TZMeu7eUj3PW5__Yzid7gpeUUiEiNa0Q; expires=Tue, 20-Jun-2017 23:11:59 GMT; path=/; domain=.google.com; HttpOnly', 'accept-ranges': 'none', 'expires': '-1', 'vary': 'Accept-Encoding', 'server': 'gws', 'connection': 'close', 'cache-control': 'private, max-age=0', 'date': 'Mon, 19 Dec 2016 23:11:59 GMT', 'p3p': 'CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."', 'content-type': 'text/html; charset=ISO-8859-1', 'x-frame-options': 'SAMEORIGIN'}, 'typeheader': 'text/html; charset=ISO-8859-1', 'encodingheader': None, 'seekable': 0, 'unixfrom': '', 'plisttext': '; charset=ISO-8859-1', 'plist': ['charset=ISO-8859-1']}
      

      以下答案中的更多信息:getting value of location header using python urllib2

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-04
        • 2017-09-22
        • 2021-10-01
        • 1970-01-01
        • 2014-05-07
        • 2016-03-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多