HTTP错误403:当我使用urllib2时禁止

时间:2018-04-25 22:36:00

标签: json urllib2

我正面临HTTP错误403:

Forbidden Exception Location: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py in http_error_default, line 558 Python Executable: /Users/kronos/Documents/venv/bin/python

这是片段:

            class FinalBuy(View):
                 def post(self,request):
                     if request.method=='POST':

                     tick=request.POST.get('ticks')
                     qty=request.POST.get('stocks')
                     #print request.get_full_path()

                     usr = self.request.user
                     t=get_object_or_404(User, 
                                            username=self.request.user)
                     um=UserMoney.objects.get(user=usr)

                     link = "http://www.google.com/finance/info? 
                              infotype=infoquoteall&q="
                     url = link+"%s:%s" % ("BOM",tick)



->                   u = urllib2.urlopen(url)
                     content = u.read()
                     data = json.loads(content[3:])
                     x= json.dumps(data)
                     info = data[0]
                     l = float(str(info["l_fix"]).replace(",",""))
                     qty=int(qty)
                     tot=qty*l



                     money=um.money
                     money=money-tot

                     um.money=money
                     um.save()

        newup=UserPorts(user=t,companies=tick,quantity=qty,boughtat=l)
        newup.save()

        return redirect('datanalyse:index')

0 个答案:

没有答案