Fallback to Python json if there is no simplejson
The json module is in Python 2.6 and up. json does not raise JSONDecodeError, but ValueError. Since JSONDecodeError is a subclass of ValueError, the except ValueError will work for both.
This commit is contained in:
parent
fda971a7f1
commit
7d0105c167
1 changed files with 6 additions and 2 deletions
|
|
@ -19,8 +19,12 @@
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
import simplejson
|
|
||||||
import urllib
|
import urllib
|
||||||
|
try:
|
||||||
|
import simplejson
|
||||||
|
except ImportError:
|
||||||
|
# Python 2.6+ has a module similar to simplejson
|
||||||
|
import json as simplejson
|
||||||
|
|
||||||
from weboob.tools.browser import BaseBrowser, BrowserUnavailable
|
from weboob.tools.browser import BaseBrowser, BrowserUnavailable
|
||||||
from weboob.tools.parsers.html5libparser import Html5libParser
|
from weboob.tools.parsers.html5libparser import Html5libParser
|
||||||
|
|
@ -303,7 +307,7 @@ class AuMBrowser(BaseBrowser):
|
||||||
def _get_chat_infos(self):
|
def _get_chat_infos(self):
|
||||||
try:
|
try:
|
||||||
json = simplejson.load(self.openurl('http://www.adopteunmec.com/1.1_cht_get.php?anticache=%f' % random.random()))
|
json = simplejson.load(self.openurl('http://www.adopteunmec.com/1.1_cht_get.php?anticache=%f' % random.random()))
|
||||||
except simplejson.JSONDecodeError:
|
except ValueError:
|
||||||
raise BrowserUnavailable()
|
raise BrowserUnavailable()
|
||||||
|
|
||||||
if json['error']:
|
if json['error']:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue