我正在尝试使用urllib2从quandl获取数据。请检查以下代码。
import json
from pymongo import MongoClient
import urllib2
import requests
import ssl
#import quandl
codes = [100526];
for id in codes:
url = 'https://www.quandl.com.com//api/v3/datasets/AMFI/"+str(id)+".json?api_key=XXXXXXXX&start_date=2013-08-30'
req = urllib2.Request(url)
response = urllib2.urlopen(req)
data = response.read()
print data
OR
for id in codes:
url = "https://www.quandl.com.com//api/v3/datasets/AMFI/"+str(id)+".json?api_key=XXXXXXXX&start_date=2013-08-30"
request = requests.get(url,verify=False)
print request
我在第一种情况下得到HTTPERROR异常404。当我使用请求模块时,即使使用verify = false,我也会收到SSL错误。我正在浏览以前的帖子,但大多数都与HTTP请求有关。
感谢您的帮助。 Ĵ
答案 0 :(得分:3)
这对我有用,但您会收到有关SSL证书的警告,但您无需关心它。
import requests
codes = [100526];
for id in codes:
url = "https://www.quandl.com.com//api/v3/datasets/AMFI/"+str(id)+".json?api_key=XXXXXXXX&start_date=2013-08-30"
request = requests.get(url, verify=False)
print request.text
request.text
有您的回复数据。
答案 1 :(得分:-1)
您似乎使用了错误的网址(.com.com
而不是.com
)以及代码第一版中不同引号的组合。请改用以下内容,它应该有效:
import urllib2
import requests
codes = [100526]
for id in codes:
url = "https://www.quandl.com//api/v3/datasets/AMFI/"+str(id)+".json?start_date=2013-08-30"
req = urllib2.Request(url)
response = urllib2.urlopen(req)
print response.read()
for id in codes:
url = "https://www.quandl.com//api/v3/datasets/AMFI/"+str(id)+".json?start_date=2013-08-30"
response = requests.get(url,verify=False)
print response.text
要停用有关SSL证书的警告,请在使用requests
发出请求之前使用the following code:
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)