'Python creating csv from Pandas and saving into Citrix ShareFile

I have a code that creates .CSV from a Pandas DataFrame. I want to save this .csv to a Citrix ShareFile folder using it's API, but am unable to do so.

I am trying to save.csv as a tempfile, and then sending that as a POST request for upload.

I am using the following code:

df = pd.DataFrame({'numbers':[1,2,3], 'colors':['red', 'white', 'blue']})
with tempfile.NamedTemporaryFile(mode='r+', suffix='.csv', delete=False) as temp:
  df.to_csv(temp, index=False, encoding='UTF-8')
  files = {'FileName': temp}
  response = requests.post(url = chunkUri, files = files)#ShareFile API to upload file
  print(response.status_code, response.reason)

I get the result as 200 OK, but there are no files in the folder. What am I doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source