python问题

以下是我下的语法,run之后出现string indices must be integers,不知道该怎样解决,有去网路上爬文仍不知道该如何解决,想问问该如何修改。

import requests
import datetime
import json

timeout = 3

try:
resp = requests.get(url="https://www.taiwanstat.com/powers/latest/", verify=True, timeout=timeout)
if resp.status_code != 200:
print('invalid url:', resp.url)

else:    try:        _obj_json = resp.json()                with open('power.json', 'w', encoding='utf-8') as f:            json.dump(_obj_json,f, indent=4)            print(type(_obj_json))                    _power_list = _obj_json        _my_power_list = []                for _power in _power_list:            _updateTime=_power['updateTime']            _eastSupply=_power['eastSupply']            _centerSupply=_power['centerSupply']            _northSupply=_power['northSupply']            _southSupply=_power['southSupply']            _southUsage=_power['southUsage']            _eastUseag=_power['eastUsage']            _northUsage=_power['northUsage']            _centerUsage=_power['centerUsage']            print("更新时间: {}, 东部及时发电量: {}, 中部及时发电量: {}, 北部及时发电量:{}, 南部及时发电量:{}, 南部及时用电量:{}, 东部及时用电量:{}, 北部及时用电量:{}, 中部及时用电量:{}".format(_updateTime, _eastSupply, _centerSupply, _northSupply, _southSupply, _southUsage, _eastUseag, _northUsage, _centerUsage))            _dbitem = [_updateTime, float(_eastSupply), float(_centerSupply), float(_northSupply), float(_southSupply), float(_southUsage), float(_eastUsage), float(_northUsage), float(_centerUsage)]            _my_stock_list.append(_dbitem)                    #with open('twse_my_0520.json', 'w', encoding='utf-8') as f:            #json.dump(_my_stock_list, f, indent=4)    except ValueError as e:        print("JSON parsing Error")

except requests.HTTPError as e:
print("The server returned an HTTP error")


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章