python - Get TimesNewswire API, HTTP Error 404: -
i getting data timesnewswire api , using tool
http://prototype.nytimes.com/gst/apitool/index.html
for example, search specific news item , type in url:
http://topics.nytimes.com/top/news/international/countriesandterritories/china/index.html?8qa
but still error " http error 404: " here python script:
from urllib2 import urlopen json import loads import codecs import time def call_the_articles(): url = "http://api.nytimes.com/svc/news/v3/content.json?&url=http%3a%2f%2ftopics.nytimes.com%2ftop%2fnews%2finternational%2fcountriesandterritories%2fchina%2findex.html%3f8qa&api-key=####" data= loads(urlopen(url).read()) posts = list() item in data["results"]: if'title' in item: posts.append(item) return posts if __name__ == '__main__': story in call_the_articles(): print story['title'].encode('ascii', 'replace')
while error shows this:
traceback (most recent call last): file "nytimes2.py", line 19, in <module> story in call_the_articles(): file "nytimes2.py", line 8, in call_the_articles data= loads(urlopen(url).read()) file "/library/frameworks/python.framework/versions/2.7/lib/python2.7/urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) file "/library/frameworks/python.framework/versions/2.7/lib/python2.7/urllib2.py", line 406, in open response = meth(req, response) file "/library/frameworks/python.framework/versions/2.7/lib/python2.7/urllib2.py", line 519, in http_response 'http', request, response, code, msg, hdrs) file "/library/frameworks/python.framework/versions/2.7/lib/python2.7/urllib2.py", line 444, in error return self._call_chain(*args) file "/library/frameworks/python.framework/versions/2.7/lib/python2.7/urllib2.py", line 378, in _call_chain result = func(*args) file "/library/frameworks/python.framework/versions/2.7/lib/python2.7/urllib2.py", line 527, in http_error_default raise httperror(req.get_full_url(), code, msg, hdrs, fp) urllib2.httperror: http error 404: not found
what problem?
Comments
Post a Comment