【发布时间】:2020-09-23 14:29:45
【问题描述】:
def location():
res = requests.get('https://ipinfo.io/')
data = res.json()
stad = data['city']
location = data['loc'].split('.')
latitude = location[0]
longitude = location[1]
return stad
def get_weather():
location(stad)
weather_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
url = 'https://api.openweathermap.org/data/2.5/weather'
# q=Amsterdam&appid=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
city = location(stad)
params = {'q': city, 'APPID': weather_key, 'units': 'metric'}
response = requests.get(url, params= params)
print(f'Het weer vandaag in Utrecht is:')
print(response.json())
尊敬的 stackoverflow 用户,
我尝试从 def location() 获取我的 from city = location(stad)((stad 表示荷兰语中的城市))
但它不起作用 python 说位置(stad)没有定义我可以做些什么来解决这个问题?
【问题讨论】:
标签: python api tkinter location weather