Skip to content

Commit 65ad7be

Browse files
committed
fetch non-json data and re-order json import so simplejson has preference
1 parent 04967b6 commit 65ad7be

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/facebook.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,13 @@
4040

4141
# Find a JSON parser
4242
try:
43-
import json
44-
_parse_json = lambda s: json.loads(s)
43+
import simplejson as json
4544
except ImportError:
4645
try:
47-
import simplejson
48-
_parse_json = lambda s: simplejson.loads(s)
46+
from django.utils import simplejson as json
4947
except ImportError:
50-
# For Google AppEngine
51-
from django.utils import simplejson
52-
_parse_json = lambda s: simplejson.loads(s)
48+
import json
49+
_parse_json = lambda s: json.loads(s)
5350

5451

5552
class GraphAPI(object):
@@ -171,12 +168,17 @@ def request(self, path, args=None, post_args=None):
171168
file = urllib.urlopen("https://graph.facebook.com/" + path + "?" +
172169
urllib.urlencode(args), post_data)
173170
try:
174-
response = _parse_json(file.read())
171+
data = file.read()
175172
finally:
176173
file.close()
177-
if response.get("error"):
178-
raise GraphAPIError(response["error"]["code"],
179-
response["error"]["message"])
174+
try:
175+
response = _parse_json(data)
176+
if response.get("error"):
177+
raise GraphAPIError(response["error"]["code"],
178+
response["error"]["message"])
179+
except ValueError:
180+
response = data
181+
180182
return response
181183

182184

0 commit comments

Comments
 (0)