我有一个工作cURL命令,它从这个特定的地方(露天,虽然我不认为这是特别的露天问题),但是当我尝试编码与python请求相同的请求,我只得到一个cookie。'在python请求响应中缺少cookie'
卷曲请求
curl -v --junk-session-cookies -H 'Content-Type: application/x-www-form-urlencoded' --cookie-jar cookies.txt --cookie cookies.txt -H 'Origin: http://<url>' -D headers.txt -e ';auto' -X POST -d @credentials http://<url>/share/page/dologin
而且蟒
r=s.post('%s/share/page/dologin' % <url>,
data=credentials, allow_redirects=False)
其中
s.headers
Out[121]: {'Origin': <url>, 'Host' :<url>, 'referer':<url> , 'Accept': '*/*', 'User-Agent': 'python-requests/2.4.1 CPython/2.7.5+ Linux/3.11.0-26-generic','Content-Type': 'application/x-www-form-urlencoded'}
设计密切匹配卷曲在发送的报头。 的allow_redirects=False
是那里反映了缺乏-L
选项。
卷曲率:
Added cookie JSESSIONID="<removed>" for domain 10.12.3.166, path /share/, expire 0 < Set-Cookie: JSESSIONID=<removed>; Path=/share/; HttpOnly * Added cookie alfLogin="<removed>" for domain 10.12.3.166, path /share, expire 1413289198 < Set-Cookie: alfLogin=<removed>; Expires=Tue, 14-Oct-2014 12:19:58 GMT; Path=/share * Added cookie alfUsername3="<obf>" for domain 10.12.3.166, path /share, expire 1413289198 < Set-Cookie: alfUsername3=<obf>; Expires=Tue, 14-Oct-2014 12:19:58 GMT; Path=/share
而我只拿到请求JSESSIONID的cookie。
更新 我愚蠢地未能包括在cURL命令中发送的头文件和收到的头文件。 那些发了
> User-Agent: curl/7.32.0
> Host: <url>
> Accept: */*
> Referer:
> Content-Type: application/x-www-form-urlencoded
> Origin: <url>
> Content-Length: 44
和头传回的
HTTP/1.1 302 Found
Server: Apache-Coyote/1.1
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Set-Cookie: JSESSIONID=<rem>; Path=/share/; HttpOnly
Set-Cookie: alfLogin=<rem>; Expires=Tue, 14-Oct-2014 12:19:58 GMT; Path=/share
Set-Cookie: alfUsername3=<rem>; Expires=Tue, 14-Oct-2014 12:19:58 GMT; Path=/share
Location: <url>/share
送回请求标题是
{'transfer-encoding': 'chunked', 'set-cookie': 'JSESSIONID=<rem>; Path=/share/; HttpOnly', 'server': 'Apache-Coyote/1.1', 'connection': 'close', 'date': 'Wed, 08 Oct 2014 08:54:53 GMT', 'content-type': 'text/html;charset=ISO-8859-1'}
我在您的请求中看不到Content_type。 – 2014-10-08 08:48:25
发现@VincentBeltman,但它在响应中没有任何变化。 – 2014-10-08 08:57:13
无论如何,'requests' *正确设置了内容类型头,只要'credentials'是一个字典。 – 2014-10-08 09:02:51