Chunks Error

pankajnegi1920
New Contributor

Chunks Error

chunksArray = jsonResponse["chunks"]
KeyError: 'chunks'

 

pankajnegi1920_0-1657712820065.png

 

Hi all, 
I have connected with Anaplan through API with help of Python .

Basically I am Exporting file from Anaplan for getting suggestion
But now If i am using my credentials and my Model it is working fine.
But for others it showing error above pasted.

Chunks are generating in my scenario but not on others

2 REPLIES 2
JaredDolich
Moderator

@pankajnegi1920 

Great question and one that can cause some challenges if the file/export is too big. I would recommend you get the chunk data first then use Python to iterate on each chunk. That should work. Here's a sample Python script to help you.

import requests
import base64
import sys
import json
from getAuthentication import userBA
from getGUIDs import wGuid, mGuid, fileID, fileName

url = (f'https://api.anaplan.com/1/3/workspaces/{wGuid}/models/{mGuid}/' +
       f'files/{fileID}/chunks')

getHeaders = {
    'Authorization': userBA
}

downloadHeaders = {
    'Authorization': userBA,
    'Accept': 'application/octet-stream'
}

getChunkData = requests.get(url,
                            headers=getHeaders)
with open('downloadChunkData.json', 'wb') as f:
    f.write(getChunkData.text.encode('utf-8'))

with open('downloadChunkData.json', 'r') as f:
    f2 = json.load(f)

with open(f'{fileName}', 'wb') as f:
    for i in f2:
        chunkData = i
        chunkID = i['id']
        print(f'Getting chunk {chunkID}')
        getChunk = requests.get(url + f'/{chunkID}',
                                headers=downloadHeaders)
        f.write(getChunk.content)
        print('Status code: ' + str(getChunk.status_code))

Jared Dolich
pankajnegi1920
New Contributor

Others export and mine has no difference in size, although they have small one.
Json response is also ok but not including Key 'chunks' in others case
Like this: 

 

{'meta': {'paging': {'currentPageSize': 0, 'offset': 0, 'totalSize': 0}, 'schema': 'https://api.anaplan.com/2/0/models/1B10FCDB61144BDA8BE3E743448B49CF/
objects/chunk'}, 'status': {'code': 200, 'message': 'Success'}}