Created
September 12, 2014 07:59
-
-
Save hyunjun/3c03cc70ed004dd801b8 to your computer and use it in GitHub Desktop.
ValueError from url to json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import re | |
import urllib | |
someUrl = '...' | |
f = urllib.urlopen(someUrl) | |
try: | |
myDict = json.load(f) | |
except ValueError: | |
# ValueError: Invalid control character at: line xxx column yyy (char zzz) | |
try: | |
myDict = json.loads(re.sub(re.compile('\s+'), '', urllib.urlopen(someUrl).read())) | |
except ValueError: | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment