1

Hello all I am trying to make an easy json with some data i pull from a type of API. I want the "key" to be one of the ids, however i get the following error "cannot fit 'int' into an index-sized integer". So looking around I think this means that the number I am trying to associate as the key is larger than a number can be?? So I was thinking about some possible work-arounds for this and was wondering if anyone knows a way to get around this. The best thing I can think of is create a dictionary with unique keys that point to that number. Please find the code below should be ready to run as is.

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

Steven
  • 139
  • 1
  • 9
  • I am not getting the error. Is this the full code ? What is the purpose of `data[id]` ? Is this OverflowError, IndexError or something else ? – Kate Jan 26 '20 at 01:46
  • Yes this is my full code minus some commented out code let me update with everything including comments and exact error. Data[id] is just to produce the error without the needed commented out section below – Steven Jan 26 '20 at 01:49
  • Sorry I am not able to reproduce your issue, but line 14 seems to be `data[id]`. Why don't you just remove this line and test again ? If you're looking for a json to csv converter [pandas](https://pandas.pydata.org/pandas-docs/stable/index.html) could do the job in two lines of code, if you have simple JSON that doesn't contain nested objects. – Kate Jan 26 '20 at 02:09
  • My end goal will be to store this in an sql db. But currently just going to write to a txt file. I did remove and uncomment that section and still get that error `[Running] python -u "d:\Code\EveFinance\dataSort.py" 5586835679 Traceback (most recent call last): File "d:\Code\EveFinance\dataSort.py", line 14, in data[id].append({ IndexError: cannot fit 'int' into an index-sized integer [Done] exited with code=1 in 1.07 seconds` – Steven Jan 26 '20 at 02:18

1 Answers1

1

Ah. I was testing your code on Linux and it looks like int is handled differently based on the platform - see: python handles long ints differently on Windows and Unix. On my setup sys.maxsize returns: 9223372036854775807. On yours (Windows) I suspect it is 536870912 (source). If I'm right you have to change your approach. Maybe use a dictionary instead of a list. Or just build your CSV strings by way of concatenation. There are many possible ways. Probably your code would work with smaller numbers.

Kate
  • 1,809
  • 1
  • 8
  • 7
  • I went ahead and made it a dict. Thanks for taking the time to help and telling me about the windows/linux differences. – Steven Jan 26 '20 at 05:57