1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

python3でsubsonicAPIを使う

1
Posted at

subsonicのAPIの使い方を調べたメモ
Basic認証使う場合は、サーバーから401コード返ってから認証する方法は使えないし注意。
どうせ暗号化されてないからu,pパラメータ使ってもいい気がするけど、どうなんだろ。

import httplib2
import base64

httplib2.debuglevel = 1 #debug出力ON
h = httplib2.Http('.cache') #引数の.cacheはキャッシュ保存ディレクトリ

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変換

_headers={'Authorization':'Basic '+ encoded} 
response, content = h.request(url,headers=_headers)

httplib2の勉強にもなった。

参考にしたサイト
http://diveintopython3-ja.rdy.jp/http-web-services.html

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?