【问题标题】:Getting Location Header Python Requests获取位置标头 Python 请求
【发布时间】:2022-08-07 23:32:22
【问题描述】:

我正在尝试向网站提交付款,我需要获取返回的 Location 标头。我试过allow_redirects=False,但我没有得到返回的标题。大多数帖子都带有会话,所以我尝试了会话和请求。

返回的标头: {\'Allow\': \'HEAD, GET\', \'Content-Length\': \'0\', \'Server\': \'\', \'Expires\': \'Wed, 13 Apr 2022 01:34:32 GMT\', \'Cache-Control\': \'max-age=0, no-cache, no-store\', \'Pragma\': \'no-cache\', \'Date\': \'Wed, 13 Apr 2022 01:34:32 GMT\', \'Connection\': \'keep-alive\', \'Server-Timing\': \'cdn-cache; desc=MISS, edge; dur=11, origin; dur=7\', \'Strict-Transport-Security\': \'max-age=31536000 ; includeSubDomains\'}

铬标题:

cache-control: max-age=0, no-cache, no-store
content-length: 0
date: Wed, 13 Apr 2022 00:48:21 GMT
expires: Wed, 13 Apr 2022 00:48:21 GMT
location: https://www.bigw.com.au/checkout/webpay/success?dts_reference=5000000315110950
pragma: no-cache
server
server-timing: cdn-cache; desc=MISS
server-timing: edge; dur=11
server-timing: origin; dur=197
set-cookie: AKA_A2=A; expires=Wed, 13-Apr-2022 01:48:21 GMT; path=/; domain=payments.woolworths.com.au; secure; HttpOnly
strict-transport-security: max-age=31536000 ; includeSubDomains

我的代码:

headers = {
                                    \'authority\': \'iframe.payments.woolworths.com.au\',
                                    \'method\': \'POST\',
                                    \'path\': \'/WOWPaymentService/webservice/continueSecureData\',
                                    \'scheme\': \'https\',
                                    \'accept\': \'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\',
                                    \'accept-encoding\': \'gzip, deflate, br\',
                                    \'accept-language\': \'en-GB,en;q=0.9\',
                                    \'cache-control\': \'max-age=0\',
                                    \'content-length\': \'147\',
                                    \'content-type\': \'application/x-www-form-urlencoded\',
                                    \'dnt\': \'1\',
                                    \'origin\': \'https://iframe.payments.woolworths.com.au\',
                                    \'referer\': link_full,
                                    \'sec-ch-ua\': \'\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"100\", \"Google Chrome\";v=\"100\"\',
                                    \'sec-ch-ua-mobile\': \'?0\',
                                    \'sec-ch-ua-platform\': \'\"Windows\"\',
                                    \'sec-fetch-dest\': \'iframe\',
                                    \'sec-fetch-mode\': \'navigate\',
                                    \'sec-fetch-site\': \'same-origin\',
                                    \'sec-fetch-user\': \'?1\',
                                    \'upgrade-insecure-requests\': \'1\',
                                    \'user-agent\': \'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36\'
                                }
                                payload = {
                                    \'card_number\': \'4007000000027\',
                                    \'exp_month\': \'04\',
                                    \'exp_year\': \'2023\',
                                    \'cv2_number\': \'456\',
                                    \'HPS_SessionID\': str(link),
                                    \'issue_number\': \'\',
                                    \'action\': \'confirm\'
                                }
                                r = requests.post(\"https://iframe.payments.woolworths.com.au/WOWPaymentService/webservice/continueSecureData\", allow_redirects=True, verify=False, json=payload, headers=headers, timeout=10)
                                print(r.url)
                                print(r.headers)

对不起,它被标记了????

任何帮助表示赞赏!

    标签: python python-3.x python-requests python-requests-html


    【解决方案1】:

    文档建议您咨询r.history 而不是r.url。

    https://docs.python-requests.org/en/latest/user/quickstart/#redirection-and-history


    另外,当你有allow_redirects=False, 我假设您已验证 r.status 是 301 还是 302? 您应该能够在应用程序级别追踪重定向。

    【讨论】:

      【解决方案2】:

      导入请求 re=requests.get(f"https://rofan.com",allow_redirects=False, timeout=5) location = (re.headers['Location'])

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-07
        • 1970-01-01
        • 2016-03-21
        • 1970-01-01
        • 2013-04-12
        相关资源
        最近更新 更多