HTTP / 1.1 401 Unauthorized(Podbean)

时间:2017-08-05 01:43:09

标签: python json django

我正在制作一个Django应用程序来上传Podbean中的.mp3文件。我尝试通过'终端'上传文件这是成功的。但现在我想通过我的应用程序上传文件。要实现这一点,我必须遵循3个步骤。首先,我必须通过requests.post授权该文件,并在json中获取结果。然后从json数据我想专门得到一些数据。我尝试了以下查询但出现错误。如果第一步将实现,那么我可以轻松地完成其他步骤。

views.py

from django.shortcuts import render
import requests
import os, json
import httplib as http_client
http_client.HTTPConnection.debuglevel = 2

def upload_recordings(request):
    file_name = "/slayer.mp3"
    file_size = 1291021
    file_path = "path"
    title = "recording1"
    access_token = "1234567890"

    url = "https://api.podbean.com/v1/files/uploadAuthorize"
    data = {'access_token': access_token, 'filename': file_name, 'filesize': file_size}
    headers = {'Content-type': 'audio/mpeg'}
    r = requests.post(url, data=json.dumps(data), headers=headers)
    j = json.loads(r.text)
    print(j)
    return render(request, 'upload.html')

我收到以下错误:

send: 'POST /v1/files/uploadAuthorize HTTP/1.1\r\nHost: api.podbean.com\r\nConnection: keep-alive\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nUser-Agent: python-requests/2.18.3\r\nContent-type: audio/mpeg\r\nContent-Length: 108\r\n\r\n{"access_token": "1234567890", "filesize": 1291021, "filename": "/slayer.mp3"}'
reply: 'HTTP/1.1 401 Unauthorized\r\n'
header: Cache-control: no-cache="set-cookie"
header: Content-Type: application/json
header: Date: Sat, 05 Aug 2017 02:05:00 GMT
header: Server: Microsoft-IIS/6.0 Version 6.0 SSL TLS AntiSpam Mozilla 4.0 OS3
header: Set-Cookie: AWSELB=830BDD2714C96857D7F5E2533BF21492F4232C62646AC64AC5598D0BC21EBA8E9430BBD3332436913229AF2BA0BC6C26AA4E11A7088C5B56673E72BAACABF3FBFB98B00339;PATH=/;MAX-AGE=600
header: WWW-Authenticate: Bearer realm="Service"
header: X-Frame-Options: DENY
header: Content-Length: 2
header: Connection: keep-alive
('-------------j', [])

0 个答案:

没有答案