"Upload Failed" error for CSV bulk upload via API

Hello,

I am currently trying to use the “categoryUser.addFromBulkUpload()” function to upload a CSV file. I am using the Kaltura Python Client Library (http://www.kaltura.com/api_v3/testme/client-libs.php) to access the Kaltura API on the SaaS (www.kaltura.com) server.

When I tested this on the API Test Console (https://developer.kaltura.com/console/#/categoryUser.addFromBulkUpload), it worked fine. I then adapted the provided sample code to Python. However, when I try to test it, I get the following error:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Users\ccrowe3\GitHub\mediahopper\hopper_project\users_upload\helpers.py", line 35, in bulk_upload_kaltura
    return client.categoryUser.addFromBulkUpload(filename, bulk_upload_data, category_user_data)
  File "C:\Users\ccrowe3\venv3\lib\site-packages\KalturaClient\Plugins\Core.py", line 48588, in addFromBulkUpload
    resultNode = self.client.doQueue()
  File "C:\Users\ccrowe3\venv3\lib\site-packages\KalturaClient\Client.py", line 327, in doQueue
    resultNode = self.parsePostResult(postResult)
  File "C:\Users\ccrowe3\venv3\lib\site-packages\KalturaClient\Client.py", line 301, in parsePostResult
    self.throwExceptionIfError(resultNode)
  File "C:\Users\ccrowe3\venv3\lib\site-packages\KalturaClient\Client.py", line 375, in throwExceptionIfError
    raise exceptionObj
KalturaException: Upload failed (UPLOAD_ERROR)

Here is the code I am using for the upload:

from KalturaClient import *

    def bulk_upload_kaltura(client, filename):
        bulk_upload_data = Plugins.Core.KalturaBulkUploadJobData()
        category_user_data = Plugins.Core.KalturaBulkUploadCategoryUserData()
        return client.categoryUser.addFromBulkUpload(filename, bulk_upload_data, category_user_data)

Where client is a KalturaClient object (correctly formed as far as I can tell, as it works for other API calls) and filename is the path to the CSV file I want to upload.

I can’t figure out what is causing this error, or even if my code is entirely incorrect. Does anybody know what is going wrong?
Thanks!

Hi,

Please try passing a file object like this:

return client.categoryUser.addFromBulkUpload(file(filename, 'rb'), bulk_upload_data, category_user_data)

instead of the literal file path:

return client.categoryUser.addFromBulkUpload(filename, bulk_upload_data, category_user_data)

Thanks,

Ok, I have just tried this but now I am getting an internal server error…?

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Users\ccrowe3\GitHub\mediahopper\hopper_project\users_upload\helpers.py", line 36, in bulk_upload_kaltura
    return client.categoryUser.addFromBulkUpload(file(filename, 'rb'), bulk_upload_data, category_user_data)
  File "C:\Users\ccrowe3\venv3\lib\site-packages\KalturaClient\Plugins\Core.py", line 48588, in addFromBulkUpload
    resultNode = self.client.doQueue()
  File "C:\Users\ccrowe3\venv3\lib\site-packages\KalturaClient\Client.py", line 324, in doQueue
    postResult = self.doHttpRequest(url, params, files)
  File "C:\Users\ccrowe3\venv3\lib\site-packages\KalturaClient\Client.py", line 274, in doHttpRequest
    f = self.openRequestUrl(url, params, files, self.requestHeaders)
  File "C:\Users\ccrowe3\venv3\lib\site-packages\KalturaClient\Client.py", line 237, in openRequestUrl
    raise KalturaClientException(e, KalturaClientException.ERROR_CONNECTION_FAILED)
KalturaClientException: HTTP Error 500: Internal Server Error (-4)

Seems you now have unrelated connectivity issues. Are you getting a proper client back from the API server?

As far as I can tell, I would say I am. I can use it for other API calls (I have just tested it with client.media.get() and it returned the correct media entry), and when I inspected it it seemed to have all the expected attributes (to my knowledge).