iCHAIT / moviemon

:movie_camera: Everything about your movies within the command line.
https://ichait.github.io/moviemon/
MIT License
208 stars 16 forks source link

json.decoder.JSONDecodeError when indexing #10

Closed hashhar closed 7 years ago

hashhar commented 8 years ago
G:\Entertainment>moviemon G:\Entertainment\Movies

Indexing all movies inside  G:\Entertainment\Movies

283it [00:00, 3557.25it/s]
  5%|4         | 13.0/276 [00:07<02:12, 1.98B/s]
Traceback (most recent call last):
  File "c:\anaconda3\lib\runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Anaconda3\Scripts\moviemon.exe\__main__.py", line 9, in <module>
  File "c:\anaconda3\lib\site-packages\moviemon\moviemon.py", line 61, in main
    util(args)
  File "c:\anaconda3\lib\site-packages\moviemon\moviemon.py", line 77, in util
    scan_dir(docopt_args["PATH"], dir_json)
  File "c:\anaconda3\lib\site-packages\moviemon\moviemon.py", line 281, in scan_dir
    data = get_movie_info(name)
  File "c:\anaconda3\lib\site-packages\moviemon\moviemon.py", line 300, in get_movie_info
    return omdb(movie_info['title'], movie_info['year'])
  File "c:\anaconda3\lib\site-packages\moviemon\moviemon.py", line 318, in omdb
    return json.loads(requests.get(url).text)
  File "c:\anaconda3\lib\json\__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "c:\anaconda3\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "c:\anaconda3\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Rerunning the command goes okay but fails in the same manner but at a different percentage. I'll try running from source and report.

hashhar commented 8 years ago

It looks to be an issue with my internet connection. Sometimes the requests.get(url) doesn't return a JSON header and instead returns an access denied page due to my college's internet which causes json.loads() to choke.

Maybe you could check if r=requests.get(url).headers['content-type'] is application/json or not.

iCHAIT commented 8 years ago

PR welcome :smile:

hashhar commented 7 years ago

@iCHAIT See the PR. Sorry for being so late. I totally forgot about this.

iCHAIT commented 7 years ago

Fixed by #11