I
I
Itvanya2015-11-17 14:04:42
Python
Itvanya, 2015-11-17 14:04:42

Python httplib2: why don't cookies work correctly after authentication process?

Friends, I decided to log in to vk.com using httplib2. I did something like this before on Requests, but I can't figure out why it doesn't work on httplib2. The code:

import httplib2
from urllib.parse import urlencode

http_hand = httplib2.Http('.cache')

url = 'http://vk.com/login.php'
body = {"email": "[email protected]", "pass": "custom_pass_123"}
headers = {'Content-type': 'application/x-www-form-urlencoded'}

(resp, content) = http_hand.request(url, 'POST', headers=headers, body=urlencode(body))
print(resp) #статус - 200, куки пришли

headers = {'Cookie': resp['set-cookie']} #Копируем куки из пришедшего нам ответа в headers
(resp1, content1) = http_hand.request('http://vk.com/settings', 'GET', headers=headers) # get запрос

I looked in the debug mode, everything is sent, all headers arrive correctly, but the 'GET' request does not pass under authentication, despite the fact that the headers passed to it contain cookies received from resp. Guys, what's the problem? I do not see a fundamental difference, but Request does the same without problems. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2015-11-17
@Itvanya

"I bought a Nissan - .. deal with it myself"
requests would never have happened if httplib worked out of the box,
and requests are placed on top very easily, in comparison with the same cURL,
but if you want perfectionism so much - earn money, see fiddlerome, read
stackoverflow.com/questions/7340818/python-3-httpl...
stackoverflow.com/questions/2296654/python-regex-h...
stackoverflow.com/questions/1738227/httplib2-how-t...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question