[英]Catch the 400 Bad request before stopping the script
I downloaded files like this and it sometimes returns 400 request. 我下载了这样的文件,有时返回400请求。
f = urllib.request.urlretrieve(url,"filename")
So I would like to check if it returns 400 error ,skip and continue to the next procedure. 因此,我想检查它是否返回400错误,跳过并继续下一个过程。
However if it returns 400 , the program stops with this error. 但是,如果返回400,程序将因该错误而停止。
urllib.error.HTTPError: HTTP Error 400: Bad Request
How can I don't let 400 error
stop the program? 我怎么不让
400 error
停止程序?
Use try catch blocks. 使用try catch块。 Assuming that
urllib
is already imported 假设
urllib
已经导入
try:
f = urllib.request.urlretrieve(url,"filename")
except urllib.error.HTTPError as e:
print("Error: ", e)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.