🐍

【Python】Lambdaで外部APIを使う

2024/02/04に公開

requestsは別途installしてimportする必要があるのでurllib3を使う

import json
import urllib3
from urllib3 import PoolManager

def req():

    url = f"https://sample.com"
    
    http = urllib3.PoolManager()
    response = http.request('GET', url)
    decoded_data = response.data.decode('utf-8')
    json_data = json.loads(decoded_data)

    return json_data

Discussion