[您好,我正在尝试使用从API类型提取的一些数据来制作一个简单的json。我希望“键”是ID之一,但是出现以下错误“无法将'int'装入索引大小的整数”。因此,环顾四周,我认为这意味着我要关联的数字大于键可以大于的数字?因此,我正在考虑一些可能的解决方法,并想知道是否有人知道解决此问题的方法。我能想到的最好的事情是创建一个具有唯一键的字典,该键指向该数字。请找到下面的代码,即可按原样运行。
import json
import requests
import csv
response = requests.get("https://esi.evetech.net/latest/markets/10000002/orders/?datasource=tranquility&order_type=all&page=1&type_id=34")
data = []
data.append({"duration","is_buy_order","issued","location_id","min_vloume","order_id","price","range","system_id","type_id","volume_remain","volume_total"})
with open("D:\\Code\\EveFinance\\orders.json","w") as jsonFile:
for index in response.json():
#print(index['order_id'])
id = index['order_id']
print(id)
data[id]
# data[id].append({
# 'duration':index['duration'],
# 'issued':index['issued'],
# 'location_id':index['location_id'],
# 'min_vloume':index['min_vloume'],
# 'price':index['price'],
# 'range':index['range'],
# 'system_id':index['system_id'],
# 'type_id':index['type_id'],
# 'volume_remain':index['volume_remain'],
# 'volume_total':index['volume_total']
# })
print(data)
#file = open("D:\\Code\\EveFinance\\orders.json","w")
#jsonString = json.dumps(data)
#file.write(jsonString)
ERROR:
[Running] python -u "d:\Code\EveFinance\dataSort.py"
5586835679
Traceback (most recent call last):
File "d:\Code\EveFinance\dataSort.py", line 14, in <module>
data[id]
IndexError: cannot fit 'int' into an index-sized integer
[Done] exited with code=1 in 0.949 seconds
啊我在Linux上测试了您的代码,看起来int
的处理方式因平台而异-请参阅:python handles long ints differently on Windows and Unix。在我的设置中,sys.maxsize
返回:9223372036854775807。在您的Windows(Windows)上,我怀疑它是536870912(source)。如果我是对的,那么您就必须改变自己的方法。也许使用字典而不是列表。或者只是通过串联方式构建CSV字符串。有很多可能的方法。可能您的代码可以使用较小的数字。