You've already forked Curso-lenguaje-python
Update requests exercise
This commit is contained in:
17
python-ofensivo/08_librerias/03_requests_11_sesion_with.py
Normal file
17
python-ofensivo/08_librerias/03_requests_11_sesion_with.py
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
|
||||
# htpps://httpbin.org/basic-auth/foo/bar
|
||||
|
||||
# Con with arrastramos una sesión
|
||||
with requests.Session() as session:
|
||||
|
||||
session.auth = ('foo', 'bar')
|
||||
response1 = session.get('https://httpbin.org/basic-auth/foo/bar')
|
||||
print(response1.text)
|
||||
|
||||
# En la segunda sesión estaremos autenticados
|
||||
response2 = session.get('https://httpbin.org/basic-auth/foo/bar')
|
||||
print(response2.text)
|
||||
|
||||
Reference in New Issue
Block a user