开发者

Unexpected behaviour with Python urllib

I am tryint to consume a JSON response but I have one very weird behaviour. The end point is a Java app running on Tomcat. I want to load the following url

http://opendata.diavgeia.gov.gr/api/dec开发者_StackOverflowisions?count=50&output=json_full&from=1

Using Ruby open-uri I load the json. If I hit in in the browser I still get the response. Once I try to use Python 's urllib or urllib2 I get an error

javax.servlet.ServletException: Could not resolve view with name 'jsonView' in servlet with name 'diavgeia-api'

It s quite a strange and I guess the error lies in the API server. Any hints ?


The server appears to need an 'Accept' header:

>>> print urllib2.urlopen(
...   urllib2.Request(
...     "http://opendata.diavgeia.gov.gr/api/decisions?count=50&output=json_full&from=1",
...     headers={"accept": "*/*"})).read()[:200]
{"model":{"queryInfo":{"total":117458,"count":50,"order":"desc","from":1},"expandedDecisions":[{"metadata":{"date":1291932000000,"tags":{"tag":[]},"decisionType":{"uid":27,"label":"ΔΑΠΑΝΗ","extr


Two possibilities, neither of which hold water:

  • The server is only prepared to use HTTP 1.1 (which urllib apparently doesn't support, but urllib2 does)
  • It's doing user agent sniffing, and rejecting Python (I tried using Firefox's UA string instead, but it still gave me an error)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜