如何返回星期几,然后从Weather API返回星期几?

时间:2018-06-19 17:48:38

标签: python weather-api

i

根据日历文档,“ new1”应采用正确的格式以返回星期几,但我收到错误消息:“ def getForecast(): zip2 = '60103' url = 'http://api.openweathermap.org/data/2.5/forecast?zip=' \ '' + zip2 + ',us&appid=7f5941b864a5fde449419c6aaca23540&units=imperial'.format(zip2) response = requests.get(url) data2 = response.json() date_list = (data2['list'][0]['dt_txt']) date_list = date_list.split() del date_list[-1] new = list(date_list[0].split('-')) new1 = [int(x) for x in new] print(calendar.weekday(new1)) ”,当我手动插入年,月,日,我一周中的哪一天都很好。

1 个答案:

答案 0 :(得分:1)

docs,您需要为year, month, day函数提供3个参数,weekday,但是您提供list,您的new1类型为{{ 1}}试试这样的

list