我有以下代码:
tries = 10
for n in range(tries):
try:
....
responsedata = requests.get(url, data=data, headers=self.hed, verify=False)
responsedata.raise_for_status()
..
if .... :
break #exit loop condition
except (ChunkedEncodingError, requests.exceptions.HTTPError) as e:
print ("page #{0} run #{1} failed. Returned status code {2}. Msg: {3}. Retry.".format(page, n, responsedata.status_code, sys.exc_info()[0]))
if n == tries - 1:
raise e # exit the process
Run Code Online (Sandbox Code Playgroud)
我看到的照片是:
page #53 run #0 failed. Returned status code 502. Msg: <class 'requests.exceptions.HTTPError'>. Retry.
page #1 run #1 failed. Returned status code …Run Code Online (Sandbox Code Playgroud) 这个问题是关于HTTP 响应代码的。
在我的 python 应用程序中,我想向用户展示与此类代码相关的文本。例如404将是Not Found。
我检查了 python 文档,但找不到为我提供代码文本/字符串的包。python 库中真的没有这样的东西吗?
解决方法是使用外部源。例如,来自 IANA 的官方 CSV 文件。