Answer the question
In order to leave comments, you need to log in
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 запрос
Answer the question
In order to leave comments, you need to log in
"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 questionAsk a Question
731 491 924 answers to any question