im trying to run my code but it show "NameError: name 'message' is not defined " but "message name is defined as shown in code" at ==> if init is True:
I'm just started api in python,
mport requests
from twilio.rest import Client
weather_id = []
API_KEY = "example"
account_sid = "AC123abc"
auth_token = "example"
client = Client(account_sid, auth_token)
para = {
"lat": 27.677904,
"lon": 78.230310,
"appid": API_KEY,
"exclude": "current, minutely, daily",
}
responced = requests.get(url="https://api.openweathermap.org/data/2.5/onecall", params=para)
responced.raise_for_status()
weather_data = responced.json()
holly_data = responced.json()["hourly"][:12]
for data in holly_data:
weather_res = data["weather"][0]["id"]
weather_id.append(weather_res)
init = False
for ids in weather_id:
if ids < 700:
init = True
if init is True:
message = client.messages.create(body="Weather Alert by S.P \n To you have a clear day \n Enjoy sir A.K.P \n "
"Thanks YOu",
from_="+19853042683",
to="+919354932229"
)
print(message.sid)