Getting more detailed error messages for automated imports

Highlighted
Contributor

Getting more detailed error messages for automated imports

I have a Python script that automates the import of a file to Anaplan:

 

fileData = {
"id" : "file_id_here",
"name" : 'file_name_here',
"chunkCount" : 1,
"delimiter" : '"',
"encoding" : "UTF-8",
"firstDataRow" : 2,
"format" : "txt",
"headerRow" : 1,
"separator" : ","
}

url = (f'https://api.anaplan.com/1/3/workspaces/{workspace_guid}/models/{model_guid}/' +
f'files/{fileData["id"]}')


# Opens the data file (filData['name'] by default) and encodes it to utf-8
dataFile = open(fileData['name'], 'r').read().encode('utf-8')

fileUpload = requests.put(url, data=dataFile)
if fileUpload.ok:
print('File Upload Successful.')
else:
print('There was an issue with your file upload: ' + str(fileUpload.status_code))

 I'm running some tests on files with errors in them. The problem I have is that the fileUpload.status_code only returns the message "There was an issue with your file upload: 401". It's not very informative or helpful. Whereas in Anaplan I might get more information about the error. Is there a way to query the Anaplan servers for this information?  

 

2 REPLIES 2
Highlighted
Super Contributor

Re: Getting more detailed error messages for automated imports

Highlighted
Master Anaplanner/Community Boss

Re: Getting more detailed error messages for automated imports

Hi Sam,

 

Looks like there's a couple of headers missing in your API request. You need the Auth header as well as the content/type header

 

The error codes unfortunately do not have any further explanation as they are just normal REST API error codes and not Anaplan specific. 401 means your request is not authenticated

 

Let me know if you need more help setting up your python script

 

Regards,

Anirudh