我正在尝试查询一个开源API,该API通过发送带有IP的GET请求来返回IP地理位置信息。
我正在使用包含IP地址(位于key1
中)的密钥测试代码。发送请求后,我正在尝试获取信息,但是我不确定自己做错了什么。
我尝试将IP附加到url的末尾(按照geoip API的指示),但是我一直收到语法错误。
import json
from botocore.vendored import requests
def lambda_handler(resp,requests,event):
event = event.key1
url = "https://freegeoip.app/json/" +event
headers = {
'accept': "application/json",'content-type': "application/json"
}
response = requests.request("GET",url,headers=headers)
print(response.text)
我下面的代码使用常规python语法工作,只是不知道如何使其与lambda一起工作
import requests
userIP = '54.81.183.174'
def theFunction():
url = "https://freegeoip.app/json/" + userIP
headers = {
'accept': "application/json",'content-type': "application/json"
}
response = requests.request("GET",headers=headers)
print(response.text)
theFunction()