python 3:urllib.error.HTTPError:HTTP错误403:禁止

时间:2020-10-25 12:09:10

标签: python json stock

我正在尝试使用以下代码获取库存数据,但出现此错误。

urllib.error.HTTPError:HTTP错误403:禁止

import urllib.request 
import json 

class GoogleFinanceAPI: 
 def __init__(self): 
    self.prefix = "http://finance.google.com/finance/info?client=ig&q=" 
 
 def get(self,symbol,exchange): 
    url = self.prefix+"%s:%s"%(exchange,symbol) 
    u = urllib.request.urlopen(url) 
    content = u.read().decode('utf-8') 
    obj = json.loads(content[3:]) 
    return obj[0] 
     
     
if __name__ == "__main__": 
  c = GoogleFinanceAPI() 
  quote = c.get("RELIANCE","NSE") 
  print(quote) 

0 个答案:

没有答案