I recently stumbled across some documentation for the unofficial Pandora API.
I decided to try this with Python 3.
After heading to the Authentication page I saw that I first had to verfiy that the service was available in my country so I did this.
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)
It prints out:
<Response [200]>
b'{"stat":"ok","result":{"isAllowed":true}}'
Right. So I'm allowed to use the partner service.
Next I saw that I had to get a Partner Login.
So I got the info it said I needed from the Partners page.
Note this is not my login info. This was partner info I was told to choose from in the documentation.
username = "android"
password = "AC7IBG09A3DTSYM4R41UJWL07VLN8JI7"
deviceModel = "android-generic"
Next, the documentation says to send a post request to one of the following links as the base url:
- http://tuner.pandora.com/services/json/
- https://tuner.pandora.com/services/json/
- http://internal-tuner.pandora.com/services/json/
- https://internal-tuner.pandora.com/services/json/
Now to encode the url parameters and put them after the base url.
It says I should take the above username
, password
, deviceModel
, the method I want to call (for partner login it says it is "auth.PartnerLogin", and the version (it says pass in the string "5") and url encode them.
So I set up the url params in urlencoded format and fire off a POST request:
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)
But when I do it prints this out and tells me there was an error:
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}'
Has anyone else used this Api before? Why am I getting an error? Am I missing something here? Apparently pithos uses this api, and it is loading music fine for me.
Can anybody point me in the right direction here please?
Looks like you passing data as parameters and using incorrect url.
Proper curl request:
I would suggest use urllib2 sample.
Here working sample for our case:
Output: