Json in the pattern.web

36 views
Skip to first unread message

John DeBovis

unread,
Mar 14, 2011, 11:32:52 AM3/14/11
to Pattern
When i try to do:
simplejson.load(URL(url)) i get AttributeError: 'URL' object has no
attribute 'read'

as opposed to:
simplejson.load(urllib.urlopen(url)) working.

I know there are some other routes I could do for this, are there any
plans on incorporating a json wrapper in pattern.web?

Tom De Smedt

unread,
Mar 14, 2011, 4:51:54 PM3/14/11
to pattern-f...@googlegroups.com
That's because 'URL' is not a file-like object (i.e., it has no read()
method). But this is easy to implement, I'll add it in the next release.

Meanwhile you can do:
simplejson.loads(URL(url).download())

Note: Pattern comes bundled with simplejson.
You can use it as follows:
from pattern.web import json
json.loads(URL(url).download())

Reply all
Reply to author
Forward
0 new messages