2013-09-30 115 views
0

在使用soundcloud python庫上傳軌道以與Soundcloud API進行交互時存在一些問題。422客戶端錯誤:未知錯誤Soundcloud API軌道上傳

錯誤日誌:

Traceback (most recent call last): 
    File "uploadToSoundcloud.py", line 25, in <module> 
    'asset_data': open('/home/jhvisser/Music/driveAt5_'+now.strftime("%y%m%d")+'.mp3', 'rb') 
    File "/usr/local/lib/python2.7/dist-packages/soundcloud/client.py", line 130, in _request 
    return wrapped_resource(make_request(method, url, kwargs)) 
    File "/usr/local/lib/python2.7/dist-packages/soundcloud/request.py", line 134, in make_request 
    result.raise_for_status() 
    File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 722, in raise_for_status 
    raise HTTPError(http_error_msg, response=self) 
requests.exceptions.422 Client Error: Unknown Error 

代碼導致錯誤。 25行是指assest_data行。

#Upload driveAtFive to SoundCloud 
driveAtFive = client.post('/tracks', driveAtFive={ 
    'title': 'Drive at 5 - ' + now.strftime("%Y-%m-%d"), 
    'sharing': 'public', 
    'asset_data': open('/home/jhvisser/Music/driveAt5_'+now.strftime("%y%m%d")+'.mp3', 'rb') 
}) 

回答

3

您需要通過track關鍵字參數。在這裏你已經命名它driveAtFive這是不正確的。將代碼示例更改爲:

driveAtFive = client.post('/tracks', track={ 
    'title': 'Drive at 5 - ' + now.strftime("%Y-%m-%d"), 
    'sharing': 'public', 
    'asset_data': open('/home/jhvisser/Music/driveAt5_'+now.strftime("%y%m%d")+'.mp3', 'rb') 
}) 

讓我知道是否有幫助。