Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONDecodeError when calling pwg.images.setMd5sum API #2114

Open
nathanzumwalt opened this issue Feb 10, 2024 · 0 comments
Open

JSONDecodeError when calling pwg.images.setMd5sum API #2114

nathanzumwalt opened this issue Feb 10, 2024 · 0 comments

Comments

@nathanzumwalt
Copy link

When all the images in the piwigo_images table have an md5sum value and the pwg.images.setMd5sum API is called, a JSONDecodeError is thrown. Issue is with the call to get_photos_no_md5sum():

$md5sum_ids_to_add = array_slice(get_photos_no_md5sum(), 0, $params['block_size']);

I have a fix in my local repo that wraps it in an if statement similar to how this is handled on the admin UI that I'll submit after I figure out pull requests:

Piwigo/admin.php

Lines 290 to 295 in 5621705

$nb_no_md5sum = count(get_photos_no_md5sum());
if ($nb_no_md5sum > 0)
{
$page['no_md5sum_number'] = $nb_no_md5sum;
}

Sample Code:

from piwigo import Piwigo

mysite = Piwigo('http://localhost')
mysite.pwg.session.login(username="______", password="__________")
pwg_token = mysite.pwg.session.getStatus()['pwg_token']

response = mysite.pwg.images.setMd5sum(block_size="20", pwg_token=pwg_token)
print(response)

Output:

nathanz@piwigo-01:~$ python3 piwigo_api_test.py
Traceback (most recent call last):
  File "/home/nathanz/.local/lib/python3.10/site-packages/piwigo/ws.py", line 124, in __call__
    result = r.json()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/nathanz/piwigo_api_test.py", line 8, in <module>
    response = mysite.pwg.images.setMd5sum(block_size="20", pwg_token=pwg_token)
  File "/home/nathanz/.local/lib/python3.10/site-packages/piwigo/ws.py", line 96, in checking
    return fn(self, **kw)
  File "/home/nathanz/.local/lib/python3.10/site-packages/piwigo/ws.py", line 135, in __call__
    raise WsErrorException(r.text)
piwigo.ws.WsErrorException: <br />
<b>Fatal error</b>:  Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 3 in /var/www/html/include/dblayer/functions_mysqli.inc.php:132
Stack trace:
#0 /var/www/html/include/dblayer/functions_mysqli.inc.php(132): mysqli-&gt;query()
#1 /var/www/html/include/dblayer/functions_mysqli.inc.php(888): pwg_query()
#2 /var/www/html/admin/include/functions.php(3294): query2array()
#3 /var/www/html/include/ws_functions/pwg.images.php(2602): add_md5sum()
#4 /var/www/html/include/ws_core.inc.php(600): ws_images_setMd5sum()
#5 /var/www/html/include/ws_protocols/rest_handler.php(41): PwgServer-&gt;invoke()
#6 /var/www/html/include/ws_core.inc.php(281): PwgRestRequestHandler-&gt;handleRequest()
#7 /var/www/html/ws.php(22): PwgServer-&gt;run()
#8 {main}
  thrown in <b>/var/www/html/include/dblayer/functions_mysqli.inc.php</b> on line <b>132</b><br />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant