2014-10-08 4 views
0

나는이 특정 (과외, 특히 야외에서 문제라고 생각하지 않지만)에서 많은 쿠키를 가져 오는 작업용 cURL 명령을 가지고 있습니다. 그러나 시도하고 인코딩 할 때 파이썬 요청과 같은 요청, 나는 단 하나의 쿠키를 얻을.파이썬 요청에 'Missing'쿠키가 있습니다.

컬 요청

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 

되고

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이 어디 파이썬은

r=s.post('%s/share/page/dologin' % <url>, 
      data=credentials, 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 쿠키를 얻을 수있는 반면.

업데이트 나는 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'} 
+0

요청에 Content_type이 표시되지 않습니다. –

+0

@VincentBeltman이 잘 보였으 나 응답에 아무것도 변경되지 않았습니다. –

+0

'credentials' *가 어쨌든 *에 의해 내용 유형 헤더가 올바르게 설정 될 것입니다.'credentials'는 사전입니다. –

답변

0

이 솔루션은 "호스트"헤더 제거했고 설정되어 있습니다 리퍼러 필드는 ''이됩니다. 나는 필요한 모든 쿠키를 얻었으므로 도움이되는 모든 의견 덕분입니다.

관련 문제