我正在使用名为混合云的服务来尝试上传一些长达一小时的播客,比如mp3文件。我一直在跟踪Mixclouds文档,我应该如何通过post请求上传歌曲,使用他们的api接口,但是我得到了一些错误。
他们说提交一个multipart/form-data POST请求,其中包含一个post请求中所需的所有数据。基于他们所说的,这里是我使用请求发布的Python代码:
accessToken = '**Censored**'
postUrl = 'https://api.mixcloud.com/upload/?access_token=' + accessToken
#postUrl = 'http://requestb.in/wqqj8lwq' ---> For testing what POST request sends.
files = {'mp3': open('/home/jhvisser/Music/driveAt5_'+now.strftime("%y%m%d")+'.mp3', 'rb'),
'name': 'z103.5 Drive at 5 Streetmix - '+now.strftime("%Y%m%d"),
'tags-0-tag': 'remix',
'tags-1-tag': 'radio',
'tags-2-tag': 'hits',
'description': 'Daily weekday uploads of the latest drive at 5 music hits'
}
r = requests.post(postUrl,files=files)我得到以下JSON作为对帖子的响应:
{
"details": {
"name": [
"This field is required."
]
},
"error": {
"message": "Some posted data was invalid",
"type": "PostValidationError"
}
}我不明白为什么它说我错过了名字字段。我有一个名字字段。其他字段可能也会出现错误,但我不确定Mixcloud应用程序是否只是在错误时停止验证。
我还向RequestBin发出了一个POST请求,这样您就可以查看从这个请求中确切地发布了什么。我将在下面包含一个链接到请求者( requestbin )页面的pastebin,因为我认为这些链接在RequestBin上过期。
PasteBin反射镜
比较而言,这里是他们在API页面上的示例如果使用CURL要做的事情:
curl -F mp3=@cloudcast.mp3 \
-F "name=API Upload" \
-F "tags-0-tag=Test" \
-F "tags-1-tag=API" \
-F "sections-0-chapter=Introduction" \
-F "sections-0-start_time=0" \
-F "sections-1-artist=Artist Name" \
-F "sections-1-song=Song Title" \
-F "sections-1-start_time=10" \
-F "percentage_music=75" \
-F "description=My test cloudcast" \
https://api.mixcloud.com/upload/?access_token=INSERT_ACCESS_TOKEN_HERE发布于 2013-10-01 22:52:53
根据文档和您所得到的错误,您应该给出一个名称
所需姓名。cloudcast的名称-这将用于生成URL,应该避免重复的名称,但不会导致上传失败。
更新
如注释中所述,使用可选参数数据发送以下值将上载文件
data={
'name': 'z103.5 Drive at 5 Streetmix - '+now.strftime("%Y%m%d"),
'tags-0-tag': 'remix',
'tags-1-tag': 'radio',
'tags-2-tag': 'hits',
'description': 'Daily weekday uploads of the latest drive at 5 music hits'
}
r = requests.post(postUrl,files=files,data=data)https://stackoverflow.com/questions/19127289
复制相似问题