mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Ensure args are properly msgpack encoded for cdb requests
This commit is contained in:
parent
1e4dae7e16
commit
52261d69d4
@ -149,7 +149,6 @@ class DBCtx(object):
|
|||||||
self.library_id = parts.fragment or None
|
self.library_id = parts.fragment or None
|
||||||
self.url = urlunparse(parts._replace(fragment='')).rstrip('/')
|
self.url = urlunparse(parts._replace(fragment='')).rstrip('/')
|
||||||
self.br = browser(handle_refresh=False, user_agent='{} {}'.format(__appname__, __version__))
|
self.br = browser(handle_refresh=False, user_agent='{} {}'.format(__appname__, __version__))
|
||||||
self.br.addheaders += [('Accept', MSGPACK_MIME), ('Content-Type', MSGPACK_MIME)]
|
|
||||||
self.is_remote = True
|
self.is_remote = True
|
||||||
username, password = read_credetials(opts)
|
username, password = read_credetials(opts)
|
||||||
self.has_credentials = False
|
self.has_credentials = False
|
||||||
@ -192,13 +191,15 @@ class DBCtx(object):
|
|||||||
raise SystemExit(err.reason)
|
raise SystemExit(err.reason)
|
||||||
|
|
||||||
def remote_run(self, name, m, *args):
|
def remote_run(self, name, m, *args):
|
||||||
from mechanize import HTTPError
|
from mechanize import HTTPError, Request
|
||||||
from calibre.utils.serialize import msgpack_loads
|
from calibre.utils.serialize import msgpack_loads, msgpack_dumps
|
||||||
url = self.url + '/cdb/run/' + name
|
url = self.url + '/cdb/run/' + name
|
||||||
if self.library_id:
|
if self.library_id:
|
||||||
url += '?' + urlencode({'library_id':self.library_id})
|
url += '?' + urlencode({'library_id':self.library_id})
|
||||||
|
rq = Request(url, data=msgpack_dumps(args),
|
||||||
|
headers={'Accept': MSGPACK_MIME, 'Content-Type': MSGPACK_MIME})
|
||||||
try:
|
try:
|
||||||
res = self.br.open_novisit(url, data=json.dumps(args))
|
res = self.br.open_novisit(rq)
|
||||||
ans = msgpack_loads(res.read())
|
ans = msgpack_loads(res.read())
|
||||||
except HTTPError as err:
|
except HTTPError as err:
|
||||||
self.interpret_http_error(err)
|
self.interpret_http_error(err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user