我有一个代理服务器查询网站。我之前的代码查询了txt文件,我想查询json对象的不同站点。我不确定txt / json是否有问题,但是一个正常,而另一个没有。以下是代码相关部分的一部分。
import urllib
import urllib2
import json
proxy_handler = urllib2.ProxyHandler({"http": http_proxy_full_auth_string})
opener = urllib2.build_opener(proxy_handler)
urllib2.install_opener(opener)
filelist = list()
filelist.append('http://www.fhfa.gov/DataTools/Downloads/Documents/HPI/HPI_AT_us_and_census.txt')
filelist.append('https://cadatacatalog.state.gov/storage/f/2013-11-24T20:56:10.098Z/validpassportsbyyear.json')
for url in filelist:
filename = url.split('/')[-1]
fhand = open(filename, 'w')
print('Retrieving', url)
uh = urllib2.urlopen(url)
响应:txt文件工作正常,但是我收到了json的错误:
URLError: <urlopen error [Errno 10061] No connection could be made because the target machine actively refused it>