A memo that investigated how to use the subsonic API When using Basic authentication, note that you cannot use the method of authenticating after returning the 401 code from the server. I think it's okay to use u and p parameters because they aren't encrypted anyway, but what about?
python
import httplib2
import base64
httplib2.debuglevel = 1 #debug output ON
h = httplib2.Http('.cache') #Of the argument.cache is the cache storage directory
top_level_url = 'http://my_server/'
url = top_level_url + 'rest/ping.view?v=1.8.0&c=myapp'
user_id = 'id'
passwd = 'pw'
encoded = str(base64.b64encode(bytes(user_id + ':' + passwd ,'utf8')),'utf-8') #base64 conversion
_headers={'Authorization':'Basic '+ encoded}
response, content = h.request(url,headers=_headers)
I also learned about httplib2.
Referenced site http://diveintopython3-ja.rdy.jp/http-web-services.html
Recommended Posts