Soundcloud Python SDK + Google App Engine Blobstore

33 views
Skip to first unread message

KenLFG via StackOverflow

unread,
Nov 13, 2013, 4:29:22 AM11/13/13
to google-appengin...@googlegroups.com

I'm trying to use the Soundcloud Python SDK to upload mp3 files to Soundcloud's API via my Google App Engine app. To accommodate the potentially large audio files being uploaded, I'm funnelling the initial uploads through to the Blobstore. I'm then trying to take the blobstore copy of the binary and pass it through the SDK so it gets uploaded.

Here's the main soundcloud part of the show:

import soundcloud

client = soundcloud.Client(
            client_id = SOUNDCLOUD_CLIENTID,
            client_secret = SOUNDCLOUD_CLIENTSECRET,
            username = SOUNDCLOUD_USERNAME,
            password = SOUNDCLOUD_PASSWORD
        )

for item in filelist:
    title = item.get('media_Id','')
    blobkey = item.get('blobkey', '')

    if blobkey:
        blob_reader = blobstore.BlobReader(str(blobkey))


        if blob_reader:
            track = client.post('/tracks', track={ 'title': title, 'sharing': 'private', 'asset_data': blob_reader })

            if track:
                item['url'] = track.permalink_url

I'm not manipulating the file in anyway. The filelist object is just an array of dicts. The error I'm getting is below (the last part shows you what that filelist object looks like.

HTTPError at /upload/processaudioupload
422 Client Error: Unknown

Request Method: POST
Request URL: http://dev.myproject.com:12080/upload/processaudioupload
Django Version: 1.4.8
Python Executable: D:\Development\Python27\pythonw.exe
Python Version: 2.7.5
Python Path: ['D:\Development\MyProject\MyProjectProject\MyProjectSite', 'D:\Development\MyProject\MyProjectProject\MyProjectSite\MyProjectSite\djangoappengine\lib', 'D:\Development\MyProject\MyProjectProject\MyProjectSite\MyProjectSite', 'D:\Program Files (x86)\Google\google_appengine', 'D:\Program Files (x86)\Google\google_appengine', 'D:\Development\Python27\DLLs', 'D:\Development\Python27\lib', 'D:\Development\Python27', 'D:\Program Files (x86)\Google\google_appengine\lib\protorpc-1.0', 'D:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3', 'D:\Program Files (x86)\Google\google_appengine\lib\webob-1.1.1', 'D:\Program Files (x86)\Google\google_appengine\lib\yaml-3.10']
Server time: Wed, 13 Nov 2013 09:11:05 +0000
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'filetransfers')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')

Traceback:
File "D:\Development\MyProject\MyProjectProject\MyProjectSite\MyProjectSite\django\core\handlers\base.py" in get_response

response = callback(request, callback_args, *callback_kwargs) File "D:\Development\MyProject\MyProjectProject\MyProjectSite\MyProjectSite\django\views\generic\base.py" in view
return self.dispatch(request, args, *kwargs) File "D:\Development\MyProject\MyProjectProject\MyProjectSite\MyProjectSite\django\views\generic\base.py" in dispatch
return handler(request, args, *kwargs) File "D:\Development\MyProject\MyProjectProject\MyProjectSite\MyProjectSite\views\cms\uploads.py" in post
track = client.post('/tracks', track={ 'title': title, 'sharing': 'private', 'asset_data': blob_reader }) File "D:\Development\MyProject\MyProjectProject\MyProjectSite\MyProjectSite\soundcloud\client.py" in _request
return wrapped_resource(make_request(method, url, kwargs)) File "D:\Development\MyProject\MyProjectProject\MyProjectSite\MyProjectSite\soundcloud\request.py" in make_request
result.raise_for_status() File "D:\Development\MyProject\MyProjectProject\MyProjectSite\MyProjectSite\requests\models.py" in raise_for_status
raise HTTPError(http_error_msg, response=self)
Exception Type: HTTPError at /upload/processaudioupload
Exception Value: 422 Client Error: Unknown
Request information:
GET: No GET data

POST:
{"files":[{"file_size":1136013,"file_name":"TestFile.mp3","media_id":"abcfa7859a54306537c7e356bfd2ab66","url":"/media/serve/jwqn_kvAlIlDZFmt2zlm7w = u'=","blobkey":"jwqn_kvAlIlDZFmt2zlm7w==","file_type":"audio/mpeg"}]}'

Now, I've tried uploading the file as a user (basically going to the soundcloud.com site, logging in and uploading it) and it works. I'm assuming at this point, the 422 error isn't just a generic fallback error if there are other problems. From their site, it says that error comes up if the file data is invalid:

http://developers.soundcloud.com/docs/api/guide#errors

I've looked in the blobstore (this is all local to my machine, I'm running the GAE SDK 1.8.7) via the SDK Console and the file is there and works (I can have it embed it in the page and it just starts to play).

Can anyone think of anything I might have missed? I've tried various ways of passing the data through (e.g. reading the blobreader and passing the output) but nothing really works. If I pass the blob data (from a read call), I get other errors which seem to just indicate the code isn't expecting to see binary or raw data in the dict--not unexpected.

I'm pressed for time so I'm sort of at a loss. I've considered trying to pass it through Google Cloud Storage since I can invoke actual file objects but I've got to get that all set up. And, in case anyone is wondering, I want to pass the audio through Soundcloud and oEmbed off what they transcode so I have options as far as playback. I don't want to require end users to support whatever audio format the original uploader used.

Any help/pointers/suggestions are appreciated!



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/19950026/soundcloud-python-sdk-google-app-engine-blobstore

KenLFG via StackOverflow

unread,
Nov 13, 2013, 9:19:50 PM11/13/13
to google-appengin...@googlegroups.com

UPDATE: I managed to get a test run working with a static file. I guess for whatever reason the SDK doesn't like the BlobReader no matter how file-like it is...I don't think I can use Soundcloud at this point.

Reply all
Reply to author
Forward
0 new messages