python script aborts on Ubuntu 16.04: No JSON object could be decoded

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

python script aborts on Ubuntu 16.04: No JSON object could be decoded

M. Fioretti-2
Hello,

I am trying to run this Python script:

https://github.com/virtadpt/Experiments/blob/master/unmark_dump_to_shaarli.py

to import a collection of bookmarks in a test install, on the SAME
Ubuntu box,
of the the Shaarli bookmark manager
https://shaarli.readthedocs.io/en/master/

After installing the python-jwt and python-requests modules, the script
starts but fails with the error message below. The behavior does not
change at all if, instead of reading the data to import from a file, I
hardwire them into the script itself one by one, i.e. if I add
statements like:

new_bookmark["url"] = "http://www.ubuntu.com"

I have already asked for support on the shaarli developers forum. I am
also asking here to be sure that it is not some Ubuntu-specific issue,
i.e. python modules packaging issues, extra settings needed, whatever.

Any help greatly appreciated,

TIA,

Marco


DEBUG: New Shaarli bookmark: {'url': 'http://www.ubuntu.com',
'description': 'this is the description of the test link', 'private':
True, 'title': 'testing shaarli with some page'}
{"url": "http://www.ubuntu.com", "description": "this is the description
of the test link", "private": true, "title": "testing shaarli with some
page"}
INFO: Sending link http://www.ubuntu.com
INFO: Starting new HTTP connection (1): 127.0.0.1
DEBUG: "POST /shaarli/ HTTP/1.1" 200 2345
Traceback (most recent call last):
   File "./unmark_dump_to_shaarli.py", line 162, in <module>
     logger.debug(json.dumps(response.json()))
   File "/usr/lib/python2.7/dist-packages/requests/models.py", line 808,
in json
     return complexjson.loads(self.text, **kwargs)
   File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
     return _default_decoder.decode(s)
   File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
   File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
     raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded




--
http://mfioretti.com

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: python script aborts on Ubuntu 16.04: No JSON object could be decoded

Oliver Grawert
hi,

> Any help greatly appreciated,
...
> ValueError: No JSON object could be decoded

a totally wild guess:

sudo apt install python-simplejson

ciao
        oli
--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: python script aborts on Ubuntu 16.04: No JSON object could be decoded

M. Fioretti-2
On 2018-08-27 20:50, Oliver Grawert wrote:
> hi,
>
>> Any help greatly appreciated,
> ...
>> ValueError: No JSON object could be decoded
>
> a totally wild guess:
>
> sudo apt install python-simplejson

Thanks Oli.

It does make some difference. If I rerun the script after installing
this module, the result is whatI pasted below (the different URL is
because this time I ran the script using the test file provided by its
developer. But even if I run the version with hardwired values it is the
same. So it is likely a library/python module version problem, at least
partly. What next?

Thanks again,
Marco



DEBUG: New Shaarli bookmark: {'url':
u'http://links.drwho.virtadpt.net/marks', 'tags': [], 'description': '',
'private': True, 'title': u'Unmark'}
INFO: Sending link http://links.drwho.virtadpt.net/marks
INFO: Starting new HTTP connection (1): 127.0.0.1
DEBUG: "POST /shaarli HTTP/1.1" 301 308
DEBUG: "GET /shaarli/ HTTP/1.1" 200 2344
Traceback (most recent call last):
   File "./unmark_dump_to_shaarli-nolinks.py", line 149, in <module>
     logger.debug(json.dumps(response.json()))
   File "/usr/lib/python2.7/dist-packages/requests/models.py", line 808,
in json
     return complexjson.loads(self.text, **kwargs)
   File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line
516, in loads
     return _default_decoder.decode(s)
   File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line
370, in decode
     obj, end = self.raw_decode(s)
   File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line
400, in raw_decode
     return self.scan_once(s, idx=_w(s, idx).end())
simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1
(char 0)

--
http://mfioretti.com

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: python script aborts on Ubuntu 16.04: No JSON object could be decoded

M. Fioretti-2
On 2018-08-27 21:53, M. Fioretti wrote:
> ...  If I rerun the script after installing
> this module, the result is whatI pasted below (the different URL is
> because this time I ran the script using the test file provided by its
> developer. But even if I run the version with hardwired values it is
> the same. So it is likely a library/python module version problem, at
> least partly.

or maybe not. If I add this statement

         print repr(response)

right before the one that prints the error message below, it prints:

<Response [200]>

IIUC, this means that shaarli answers with an HTTP response code
*instead* of something in JSON format, as expected, and is this that
causes the error:

"JSONDecodeError: Expecting value..."

by simple_json. Am I right? If yes, what now?

Thanks,
Marco

>
> DEBUG: New Shaarli bookmark: {'url':
> u'http://links.drwho.virtadpt.net/marks', 'tags': [], 'description':
> '', 'private': True, 'title': u'Unmark'}
> INFO: Sending link http://links.drwho.virtadpt.net/marks
> INFO: Starting new HTTP connection (1): 127.0.0.1
> DEBUG: "POST /shaarli HTTP/1.1" 301 308
> DEBUG: "GET /shaarli/ HTTP/1.1" 200 2344
> Traceback (most recent call last):
>   File "./unmark_dump_to_shaarli-nolinks.py", line 149, in <module>
>     logger.debug(json.dumps(response.json()))
>   File "/usr/lib/python2.7/dist-packages/requests/models.py", line 808,
> in json
>     return complexjson.loads(self.text, **kwargs)
>   File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line
> 516, in loads
>     return _default_decoder.decode(s)
>   File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line
> 370, in decode
>     obj, end = self.raw_decode(s)
>   File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line
> 400, in raw_decode
>     return self.scan_once(s, idx=_w(s, idx).end())
> simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1
> (char 0)
>
> --
> http://mfioretti.com

--
http://mfioretti.com

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: python script aborts on Ubuntu 16.04: No JSON object could be decoded

Oliver Grawert
hi,
Am Dienstag, den 28.08.2018, 06:47 +0200 schrieb M. Fioretti:


>
> right before the one that prints the error message below, it prints:
>
> <Response [200]>
>
> IIUC, this means that shaarli answers with an HTTP response code 
> *instead* of something in JSON format, as expected, and is this that 
> causes the error:
>
> "JSONDecodeError: Expecting value..."
>
> by simple_json. Am I right? If yes, what now?
>
looking at the code:

        response = requests.post(args.url+"/links",
            data=json.dumps(new_bookmark), headers=headers)

do you have the python-requests library installed ? 

in general, when using such a third party python script you should
first take a look at all the import statements at the top of the code.
then find out which deb package provides which of the imported modules
(apt-cache search and google are usually helpful with that) and install
them ...

another issue i see is that the script needs to send an api key, did
you provide one in your invocation ? 

also ... quoting from the code:

argparser.add_argument("--url", action="store", required=True,
    help="Full URL to a Shaarli instance.  Must include the /api/v1
bit.")

but your url does not seem to include /api/v1 anywhere ...


ciao
        oli
--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: python script aborts on Ubuntu 16.04: No JSON object could be decoded

M. Fioretti-2
Hello Oliver, and thanks for your continued support!

the python-request module is installed. I forgot to check if it was
installed, and the script would just abort and complain.

the apikey provided  by the shaarli installation is passed to the script

about the "Must include the /api/v1" part:

I too had noticed that. That subfolder is not present in the current
version of shaarli. When I realized that, I started passing to the
script the URL that, from my own understanding of the PHP source code
should be the one to use now. But indeed, I cannot be sure that it is
so.

Thanks,
Marco

On 2018-08-28 10:09, Oliver Grawert wrote:

> hi,
> Am Dienstag, den 28.08.2018, 06:47 +0200 schrieb M. Fioretti:
>>  
>>
>> right before the one that prints the error message below, it prints:
>>
>> <Response [200]>
>>
>> IIUC, this means that shaarli answers with an HTTP response code 
>> *instead* of something in JSON format, as expected, and is this that 
>> causes the error:
>>
>> "JSONDecodeError: Expecting value..."
>>
>> by simple_json. Am I right? If yes, what now?
>>
> looking at the code:
>
>         response = requests.post(args.url+"/links",
>             data=json.dumps(new_bookmark), headers=headers)
>
> do you have the python-requests library installed ? 
>
> in general, when using such a third party python script you should
> first take a look at all the import statements at the top of the code.
> then find out which deb package provides which of the imported modules
> (apt-cache search and google are usually helpful with that) and install
> them ...
>
> another issue i see is that the script needs to send an api key, did
> you provide one in your invocation ? 
>
> also ... quoting from the code:
>
> argparser.add_argument("--url", action="store", required=True,
>     help="Full URL to a Shaarli instance.  Must include the /api/v1
> bit.")
>
> but your url does not seem to include /api/v1 anywhere ...
>
>
> ciao
> oli

--
http://mfioretti.com

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users