0

我正在尝试编写一个脚本,它将在我的 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)

但它似乎不起作用,这意味着我没有看到图书馆更新。

我做错了什么?

4

1 回答 1

2

谁在 URL 中“root”?一切都非常简单:

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 请求。

于 2016-11-14T11:50:46.870 回答