竞技宝官网dota2python3 urllib.error.HTTPError: HTTP Error 403: Forbidden错误

2019-12-22 19:51栏目:龙竞技官网
TAG:

想学着用Python写爬虫,代码很短,如下:importurllib.parseimporturllib.requestdata=bytes(urllib.parse.urlencode({'word':'hello'}),encoding='utf8')print(data)response=urllib.request.urlopen('',data=data).read()print(response)但运行后报错Traceback(mostrecentcalllast):File"C:UsersyDesktopcrawler.py",line10,inmoduleresponse=urllib.request.urlopen('',data=data)File"C:UsersyAppDataLocalProgramsPythonPython37liburllibrequest.py",line222,inurlopenreturnopener.open(url,data,timeout)File"C:UsersyAppDataLocalProgramsPythonPython37liburllibrequest.py",line531,inopenresponse=meth(req,response)File"C:UsersyAppDataLocalProgramsPythonPython37liburllibrequest.py",line641,inhttp_response'http',request,response,code,msg,hdrs)File"C:UsersyAppDataLocalProgramsPythonPython37liburllibrequest.py",line563,inerrorresult=self._call_chain(*args)File"C:UsersyAppDataLocalProgramsPythonPython37liburllibrequest.py",line503,in_call_chainresult=func(*args)File"C:UsersyAppDataLocalProgramsPythonPython37liburllibrequest.py",line755,inhttp_error_302returnself.parent.open(new,timeout=req.timeout)File"C:UsersyAppDataLocalProgramsPythonPython37liburllibrequest.py",line531,inopenresponse=meth(req,response)File"C:UsersyAppDataLocalProgramsPythonPython37liburllibrequest.py",line641,inhttp_response'http',request,response,code,msg,hdrs)File"C:UsersyAppDataLocalProgramsPythonPython37liburllibrequest.py",line569,inerrorreturnself._call_chain(*args)File"C:UsersyAppDataLocalProgramsPythonPython37liburllibrequest.py",line503,in_call_chainresult=func(*args)File"C:UsersyAppDataLocalProgramsPythonPython37liburllibrequest.py",line649,inhttp_error_defaultraiseHTTPError(req.full_url,code,msg,hdrs,fp)urllib.error.HTTPError:HTTPError405:METHODNOTALLOWED拜托大家解答一下

通过多线程获取页数,出现的错误。1个线程没问题。错误信息如下:Traceback(mostrecentcalllast):File"E:UsersAdministratorAppDataLocalProgramsPythonPython37-32libthreading.py",line917,in_bootstrap_innerself.run()File"E:UsersAdministratorAppDataLocalProgramsPythonPython37-32libthreading.py",line865,inrunself._target(*self._args,**self._kwargs)File"downpic.py",line61,inget_page_numhtml=get_html(pop,opener1).decode('utf-8')File"downpic.py",line28,inget_htmlresponse=opener1.open(req)File"E:UsersAdministratorAppDataLocalProgramsPythonPython37-32liburllibrequest.py",line531,inopenresponse=meth(req,response)File"E:UsersAdministratorAppDataLocalProgramsPythonPython37-32liburllibrequest.py",line641,inhttp_response'http',request,response,code,msg,hdrs)File"E:UsersAdministratorAppDataLocalProgramsPythonPython37-32liburllibrequest.py",line569,inerrorreturnself._call_chain(*args)File"E:UsersAdministratorAppDataLocalProgramsPythonPython37-32liburllibrequest.py",line503,in_call_chainresult=func(*args)File"E:UsersAdministratorAppDataLocalProgramsPythonPython37-32liburllibrequest.py",line649,inhttp_error_defaultraiseHTTPError(req.full_url,code,msg,hdrs,fp)urllib.error.HTTPError:HTTPError514:

Python 3.x 中"HTTP Error 403: Forbidden"问题的解决方案

2013-09-09 13:41:01个评论

收藏我要投稿

问题:

urllib.request.urlopen() 方法经常会被用来打开一个网页的源代码,然后会去分析这个页面源代码,但是对于有的网站使用这种方法时会抛出"HTTP Error 403: Forbidden"异常

例如 执行下面的语句时

[python]

urllib.request.urlopen("")

会出现以下异常:

[python]

 File "D:Python32liburllibrequest.py", line 475, in open

response = meth(req, response)

版权声明:本文由龙竞技官网发布于龙竞技官网,转载请注明出处:竞技宝官网dota2python3 urllib.error.HTTPError: HTTP Error 403: Forbidden错误