gpt4 book ai didi

python - 此错误 : httperror_seek_wrapper: HTTP Error 404: Not Found? 的异常是什么

转载 作者:行者123 更新时间:2023-11-28 16:40:06 25 4
gpt4 key购买 nike

我想处理错误:

“httperror_seek_wrapper:HTTP 错误 404:未找到”

而是只返回一个空字符串。但我不确定 except 语句应该是什么。如果有重复的帖子,我深表歉意,但弹出的帖子似乎都没有处理这个错误,而是在更深层次上找出出了什么问题。然而,我只想传递并返回一个空字符串。

基本上,我在寻找空白处应填入的内容:

try:
....
except _____:
....

谢谢!

_____

这是抛出错误的代码。

---------------------------------------------------------------------------
httperror_seek_wrapper Traceback (most recent call last)
<ipython-input-181-e2b68bf19ff9> in <module>()
5
6 for i in range(len(first)):
----> 7 student_html = get_stud_html(first[i],last[i],'Sophomore')
8 # print type(student_html)
9 # print parse_hfb_page(student_html)

<ipython-input-177-9b1d4294820d> in get_stud_html(first, last, year)
60 #ideally will want to use a regex to do this in case there's more than one link on the page
61 stud_url = 'http://facebook.college.harvard.edu/'+links_lst[12]
---> 62 stud_html = br.open(stud_url)
63 return stud_html.get_data()
64

//anaconda/python.app/Contents/lib/python2.7/site-packages/mechanize-0.2.5-py2.7.egg/mechanize/_mechanize.pyc in open(self, url, data, timeout)
201 def open(self, url, data=None,
202 timeout=_sockettimeout._GLOBAL_DEFAULT_TIMEOUT):
--> 203 return self._mech_open(url, data, timeout=timeout)
204
205 def _mech_open(self, url, data=None, update_history=True, visit=None,

//anaconda/python.app/Contents/lib/python2.7/site-packages/mechanize-0.2.5-py2.7.egg/mechanize/_mechanize.pyc in _mech_open(self, url, data, update_history, visit, timeout)
253
254 if not success:
--> 255 raise response
256 return response
257

httperror_seek_wrapper: HTTP Error 404: Not Found

最佳答案

这是一个 urllib2.HTTPError 异常。

from urllib2 import HTTPError

try:
# ...
except HTTPError:
# ...

你可以在 source of _mechanize.py 中看到这个,其中捕获了相同的异常并将其分配给 response 以便稍后重新引发。

关于python - 此错误 : httperror_seek_wrapper: HTTP Error 404: Not Found? 的异常是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20445390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com