Created
June 20, 2018 22:39
-
-
Save CoutinhoElias/2283425b3c1963bc1b2ef5d7915bb263 to your computer and use it in GitHub Desktop.
Conexão python usando cookies para Logar d-já Vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.parse, urllib.request | |
import http.client, http.cookiejar | |
cookie = http.cookiejar.CookieJar() | |
conn = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie)) | |
#self._conn.addheaders = [('Content-Type', 'multipart/form-data')] | |
url = 'http://localhost/api/login' | |
url_todos = 'http://localhost/api/list_todos' | |
param = { | |
'username':'elias', | |
'password':'senha123' | |
} | |
#converte dicionário para formato url | |
param_ = urllib.parse.urlencode(param).encode("utf-8") | |
res = conn.open(url, param_) | |
#res = conn.post(url, data=param) | |
#res.status | |
print(res.read()) | |
#print(res.status) | |
print('----------------------------------') | |
res_todos = conn.open(url_todos) | |
print(res_todos.read()) | |
print(res_todos.status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment