422客户端错误:未知错误Soundcloud API跟踪上载

时间:2013-09-30 18:42:05

标签: python soundcloud

使用soundcloud python库上传曲目时遇到一些问题,无法与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')
})

1 个答案:

答案 0 :(得分: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')
})

如果有帮助,请告诉我。