我正在尝试编写一个运行“更新库”的脚本'命令我的XBMC。
当我尝试跑步时:
url = 'http://root:libreelec@%IP_ADDRESS%:12345/jsonrpc?request={"jsonrpc": "2.0", "method": "VideoLibrary.Scan"}'
r = requests.get(url)
我看到该库已更新,但我收到以下错误:
Traceback (most recent call last):
File "<input>", line 2, in <module>
File "C:\Python27\lib\site-packages\requests\api.py", line 70, in get
return request('get', url, params=params, **kwargs)
File "C:\Python27\lib\site-packages\requests\api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 596, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\lib\site-packages\requests\adapters.py", line 473, in send
raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', BadStatusLine("''",))
我试图将代码修改为:
url = 'http://root:libreelec@%IP_ADDRESS%:12345/jsonrpc?'
data = json.dumps({"request": {"jsonrpc": "2.0", "method": "VideoLibrary.Scan"}})
r = requests.get(url, params=data)
但它似乎不起作用,这意味着我没有看到图书馆更新。
我做错了什么?
答案 0 :(得分:2)
谁&#39; root&#39;在URL中?一切都很简单:
url = 'http://libreelec:12345/jsonrpc'
data = {"jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": "1"}
r = requests.post(url, json=data)
/json
端点也接受POST,request.post
会将dict
处理为适当的JSON请求。