city_info = {
'city': city,
'temp': res['main']['temp'],
'weatherDescription': res['weather']['description'],
'icon': res['weather']['icon'],
'windSpeed': res['wind']['speed'],
}
Почему, когда я вызываю объект «погода» API OpenWetherMap, у меня возникает ошибка типа:
TypeError: list indices must be integers or slices, not str
Я использую Python 3.8.2 и Django 3.1
Полный код:
from django.shortcuts import render
import requests
def index(request):
# This is MINE API key! You can change it to yours, if you need it.
apiKey = '8bf70752121d2f2366e66d73f3445966'
url = 'https://api.openweathermap.org/data/2.5 ... ric&appid=' + apiKey
city = 'Washington'
res = requests.get(url.format(city)).json()
city_info = {
'city': city,
'temp': res['main']['temp'],
'weatherDescription': res['weather']['description'],
'icon': res['weather']['icon'],
'windSpeed': res['wind']['speed'],
}
context = {'info': city_info}
return render(request, 'weather/index.html', context)
Подробнее здесь: https://stackoverflow.com/questions/632 ... ango-3-1-c
Python TypeError: индексы списка должны быть целыми числами или срезами, а не строкой, Django 3.1 ЗАКРЫТО ⇐ Python
Программы на Python
1737454818
Anonymous
city_info = {
'city': city,
'temp': res['main']['temp'],
'weatherDescription': res['weather']['description'],
'icon': res['weather']['icon'],
'windSpeed': res['wind']['speed'],
}
Почему, когда я вызываю объект «погода» API OpenWetherMap, у меня возникает ошибка типа:
TypeError: list indices must be integers or slices, not str
Я использую Python 3.8.2 и Django 3.1
Полный код:
from django.shortcuts import render
import requests
def index(request):
# This is MINE API key! You can change it to yours, if you need it.
apiKey = '8bf70752121d2f2366e66d73f3445966'
url = 'https://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid=' + apiKey
city = 'Washington'
res = requests.get(url.format(city)).json()
city_info = {
'city': city,
'temp': res['main']['temp'],
'weatherDescription': res['weather']['description'],
'icon': res['weather']['icon'],
'windSpeed': res['wind']['speed'],
}
context = {'info': city_info}
return render(request, 'weather/index.html', context)
Подробнее здесь: [url]https://stackoverflow.com/questions/63271384/python-typeerror-list-indices-must-be-integers-or-slices-not-str-django-3-1-c[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия