2017-07-14 192 views
0

我目前正在使用python请求模块在网站上执行自动HTTP任务。 问题是我的控制台没有得到与我的浏览器相同的结果。使用python请求POST请求时丢失头文件

这是我得到让我的浏览器中的POST请求时:

enter image description here

这是我得到使通过Python请求模块的POST请求,该请求运行.headers方法时:

{ 
     'Date': 'Fri, 14 Jul 2017 15:19:22 GMT', 
     'Content-Type': 'text/html; charset=utf-8', 
     'Transfer-Encoding': 'chunked', 
     'Connection': 'keep-alive', 
     'Cache-Control': 'private', 
     'Location': '/cart/view', 
     'Set-Cookie': 'png.notice=9Hz8GWQ38JQZqTrqcsnn1J5nfgIZt71orHtf71mI+rwqFpQg4RnV7BqZni/GgIS/SmUnC4jgnhjQuDhZNW2adxeLctG+bToT0wTTbgxe40t5RmbVv1viuH2gkL1eH2xN3IavOUBhVXm+JlQrmVnHLocqjgvWi8wAClLYmrShY1U2ege9; expires=Fri, 14-Jul-2017 15:34:03 GMT; path=/; HttpOnly', 
     'X-Powered-By': 'ASP.NET', 
     'X-UA-Compatible': 'IE=Edge,chrome=1', 
     'Server': 'cloudflare-nginx', 
     'CF-RAY': '37e575befbf43c35-CDG' 
    } 

注意两个结果是完全不同的。 我试图得到响应头里面的“位置”标头(带有开始“https://live.adyen.com/hpp ...” 我在做什么错在这里

编辑:?这是我的源代码:

request = session.post('https://www.nakedcph.com/cart/process', data=user_info) 
    request.url 
    # outputs 'https://www.nakedcph.com/cart/view' (probably the issue) 
    request.headers 
    # outputs the headers (but not all of them?) 

PS:使POST请求后,网站重定向到URL从响应头“位置”水箱内

enter image description here

+0

你是如何通过python发出请求的?你的代码是什么样的?你通过python传递的头文件与浏览器的头文件不同。这是一个重要的细节。 –

+0

刚刚添加了我的源代码。我不明白的是请求模块正在输出什么样的头文件。它是响应头还是请求头? –

+0

请求标头。尝试'session.post('https://www.nakedcph.com/cart/process',headers = {'User-Agent':'Mozilla/5.0'},data = user_info)' –

回答

0

我想通了米。在发布请求中包含一些参数。我的错。