@@ -938,9 +938,6 @@ def fetch(self, refresh_url=None, timeout=10):
938
938
elif "application/javascript" in headers ["content-type" ]:
939
939
content_type = CONTENT_JSON
940
940
else :
941
- print (
942
- "HTTP Error {}: {}" .format (r .status_code , r .reason .decode ("utf-8" ))
943
- )
944
941
if self ._debug :
945
942
if "content-length" in headers :
946
943
print (
@@ -949,7 +946,9 @@ def fetch(self, refresh_url=None, timeout=10):
949
946
if "date" in headers :
950
947
print ("Date: {}" .format (headers ["date" ]))
951
948
self .neo_status ((100 , 0 , 0 )) # red = http error
952
- return None
949
+ raise OSError (
950
+ "HTTP {}: {}" .format (r .status_code , r .reason .decode ("utf-8" ))
951
+ )
953
952
954
953
if self ._debug and content_type == CONTENT_TEXT :
955
954
print (r .text )
@@ -993,11 +992,17 @@ def fetch(self, refresh_url=None, timeout=10):
993
992
except KeyError :
994
993
print (json_out )
995
994
raise
996
- elif self ._regexp_path :
995
+ elif content_type == CONTENT_TEXT and self ._regexp_path :
997
996
for regexp in self ._regexp_path :
998
997
values .append (re .search (regexp , r .text ).group (1 ))
999
998
else :
1000
- values = r .text
999
+ if content_type == CONTENT_JSON :
1000
+ # No path given, so return JSON as string for compatibility
1001
+ import json # pylint: disable=import-outside-toplevel
1002
+
1003
+ values = json .dumps (r .json ())
1004
+ else :
1005
+ values = r .text
1001
1006
1002
1007
if self ._image_json_path :
1003
1008
try :
0 commit comments