Skip to content

Instantly share code, notes, and snippets.

@hyunjun
Created September 12, 2014 07:59
Show Gist options
  • Save hyunjun/3c03cc70ed004dd801b8 to your computer and use it in GitHub Desktop.
Save hyunjun/3c03cc70ed004dd801b8 to your computer and use it in GitHub Desktop.
ValueError from url to json
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