43 lines
708 B
Markdown
43 lines
708 B
Markdown
![]() |
+++
|
||
|
title = "URL"
|
||
|
weight = 8
|
||
|
+++
|
||
|
|
||
|
### get
|
||
|
|
||
|
Método `get`.
|
||
|
|
||
|
```python
|
||
|
def prueba_get():
|
||
|
|
||
|
url = 'https://api.ipify.org'
|
||
|
respuesta = app.url.get(url)
|
||
|
if respuesta.status_code == 200:
|
||
|
mi_ip = respuesta.body.decode()
|
||
|
app.debug(f'IP: {mi_ip}')
|
||
|
else:
|
||
|
app.debug(respuesta.status_code)
|
||
|
|
||
|
return
|
||
|
```
|
||
|
|
||
|
```
|
||
|
16/08/2022 22:14:13 - DEBUG - IP: 199.203.174.159
|
||
|
```
|
||
|
|
||
|
Respuestas en formato json.
|
||
|
|
||
|
```python
|
||
|
def prueba_get():
|
||
|
|
||
|
url = 'https://api.ipify.org/?format=json'
|
||
|
respuesta = app.url.get(url)
|
||
|
if respuesta.status_code == 200:
|
||
|
datos = respuesta.json()
|
||
|
app.debug(f'IP: {datos["ip"]}')
|
||
|
else:
|
||
|
app.debug(respuesta.status_code)
|
||
|
|
||
|
return
|
||
|
```
|