Pandora Api auth.partnerLogin 给出错误

Pandora Api auth.partnerLogin giving error

我最近偶然发现了 some documentation for the unofficial Pandora API.

我决定用 Python 3.

试试这个

前往 the Authentication page 后,我看到我首先必须确认该服务在我的国家/地区可用,所以我这样做了。

import requests
import urllib

url = "http://internal-tuner.pandora.com/services/json/?method=test.checkLicensing"

res = requests.post(url)

print(res.status_code)
print(res.content)

它打印出来:

<Response [200]>
b'{"stat":"ok","result":{"isAllowed":true}}'

没错。所以我可以使用合作伙伴服务。

接下来我看到我必须获得 合作伙伴登录

所以我从 the Partners page.

那里得到了它说我需要的信息

注意这不是我的登录信息。这是我在文档中被告知要选择的合作伙伴信息。

username = "android"
password = "AC7IBG09A3DTSYM4R41UJWL07VLN8JI7"
deviceModel = "android-generic"

接下来,文档说将 post 请求发送到以下链接之一作为 base url:

现在对 url 参数进行编码并将它们放在基础 url 之后。 它说我应该采用上面的usernamepassworddeviceModel,我想调用的方法(对于合作伙伴登录,它说它是"auth.PartnerLogin",以及版本(它说传入字符串 "5") 并 url 对其进行编码。

所以我以 url 编码格式设置 url 参数并触发 POST 请求:

import requests
import urllib

url = "http://internal-tuner.pandora.com/services/json/?"

username = "android"
password = "AC7IBG09A3DTSYM4R41UJWL07VLN8JI7"
deviceModel = "android-generic"

data = {
    "method": "auth.partnerLogin",
    "username": username,
    "password": password,
    "deviceModel": deviceModel,
    "version": "5"
}

url += urllib.parse.urlencode(data)

res = requests.post(url)

print("url:", url)
print("response:", res)
print("content:", res.content)

但是当我这样做时它打印出来并告诉我有一个错误:

url: http://internal-tuner.pandora.com/services/json/?method=auth.partnerLogin&username=android&password=AC7IBG09A3DTSYM4R41UJWL07VLN8JI7&deviceModel=android-generic&version=5
response: <Response [200]>
content: b'{"stat":"fail","message":"An unexpected error occurred","code":9}'

其他人以前用过这个 Api 吗? 为什么我会收到错误消息?我在这里错过了什么吗? 显然 pithos 使用这个 api,它正在加载音乐对我来说很好。

有人能给我指出正确的方向吗?

您似乎将数据作为参数传递并使用了不正确的 url。

正确的curl请求:

########## REQUEST ##########
curl  -i  --data '{ "username": "android", "password": "AC7IBG09A3DTSYM4R41UJWL07VLN8JI7", "deviceModel": "android-generic", "version": "5", "includeUrls": true }' -X POST 'https://tuner.pandora.com:443/services/json/?method=auth.partnerLogin'   -H "Content-Type: application/json"  -A 'pinobar'
########## OUTPUT ##########
HTTP/1.1 200 OK
Date: Thu, 04 Jan 2018 03:46:54 GMT
Server: Apache
Content-Type: text/plain; charset=utf-8
Content-Length: 741
Cache-Control: must-revalidate, max-age=0
Expires: -1
Vary: Accept-Encoding

{"stat":"ok","result":{"syncTime":"f6f071bb4b886bc3545fbd66701b8d38","deviceProperties":{"followOnAdRefreshInterval":3,"ooyala":{"streamingPercentage":0,"streamingWhitelist":[534051315],"videoAdBufferRetryCount":3,"videoAdLoadingTimeout":2,"videoAdPlayTimeout":8},"videoAdUniqueInterval":0,"videoAdStartInterval":180,"optionalFeatures":{"optionalFeature":[{"feature":"useAudioProxy2","enabled":"false","platformVersionRange":{"low":"4.0","high":"5.0.0"},"productVersionRange":{"low":"1.6","high":"*"}}]},"adRefreshInterval":3,"videoAdRefreshInterval":870},"partnerAuthToken":"VADEjNzUq9Ew9HUkIzUT489kVe9kjo0If3","partnerId":"42","stationSkipUnit":"hour","urls":{"autoComplete":"http://autocomplete.pandora.com/search"},"stationSkipLimit":6}}

我建议使用 urllib2 sample.

这里是我们案例的工作示例:

import json
import urllib2

username    = "android"
password    = "AC7IBG09A3DTSYM4R41UJWL07VLN8JI7"
deviceModel = "android-generic"
url         = "https://tuner.pandora.com:443/services/json/?method=auth.partnerLogin"

values = {
    "username"   : username,
    "password"   : password,
    "deviceModel": deviceModel,
    "version"    : "5"
}

data = json.dumps(values)
headers = {'content-type': 'application/json'}
req = urllib2.Request(url, data, headers)
response = urllib2.urlopen(req)
content = response.read()

print("data:", data)
print("url:", url)
print("response:", response)
print("content:", content)

输出:

('url:', 'https://tuner.pandora.com:443/services/json/?method=auth.partnerLogin')
('response:', <addinfourl at 4509594832 whose fp = <socket._fileobject object at 0x10c7c0bd0>>)
('content:', '{"stat":"ok","result":{"stationSkipLimit":6,"partnerId":"42","partnerAuthToken":"VAEIniGnwSV1exsWHgUcsQgV5HA63B1nFA","syncTime":"4663310634ae885f45f489b2ab918a66","deviceProperties":{"followOnAdRefreshInterval":3,"ooyala":{"streamingPercentage":0,"streamingWhitelist":[534051315],"videoAdBufferRetryCount":3,"videoAdLoadingTimeout":2,"videoAdPlayTimeout":8},"videoAdUniqueInterval":0,"videoAdStartInterval":180,"optionalFeatures":{"optionalFeature":[{"feature":"useAudioProxy2","enabled":"false","platformVersionRange":{"low":"4.0","high":"5.0.0"},"productVersionRange":{"low":"1.6","high":"*"}}]},"adRefreshInterval":3,"videoAdRefreshInterval":870},"stationSkipUnit":"hour"}}')