本帖最后由 十月故里 于 2020-4-1 21:18 编辑
不是这么说的,看最后一行的就行,它类似牵一发动全身,由于一个地方错误引起的一连串程序运行错误而已,但关键就是看返回信息的最后一句说的啥,调用的库除开,就看你代码块部分的错误的最后一行,我给你捋捋
Traceback (most recent call last):
File "C:\Users\39436\Desktop\python练习\download_mm.py", line 60, in <module>
download_mm()
File "C:\Users\39436\Desktop\python练习\download_mm.py", line 51, in download_mm
page_num = int(get_page(url))
File "C:\Users\39436\Desktop\python练习\download_mm.py", line 13, in get_page
html = url_open(url).decode(utf-8)
File "C:\Users\39436\Desktop\python练习\download_mm.py", line 7, in url_open
response = urllib.request.urlopen(url)
File "C:\Users\39436\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\39436\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 531, in open
response = meth(req, response)
File "C:\Users\39436\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 640, in http_response
response = self.parent.error(
File "C:\Users\39436\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 569, in error
return self._call_chain(*args)
File "C:\Users\39436\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 502, in _call_chain
result = func(*args)
File "C:\Users\39436\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
这是你的反错信息(两行为一组,第一行告诉你错误的地方在第几行,第二行告诉你错误的是代码具体是什么)
你看第一段说在执行 download_mm()的时候引起的错误,而这个错误的地方在哪里
这时候看第二段 page_num = int(get_page(url)),同样这里引起的错误在哪里,依次类推
到属于你代码的最后一部分就是错误的根源response = urllib.request.urlopen(url)
然后后面的部分属于引用库里面的函数调用,直接看最后一行
HTTP Error 403: Forbidden,就是说你在用urllib.request.urlopen(url),打开这个链接的时候,由于对面不应答或者url本来是错的,导致你的代码运行出错