try
r = requests.get(url,headers={'User-Agent': ua.random},timeout=timeout) # execute a timed website request
if r.status_code > 299: # check for bad status
r.raise_for_status() # if confirmed raise bad status
else:
print(r.status_code, url) # otherwise print status code and url
except Exception as e:
print('\nThe following exception: {0}, \nhas been found found on the following post: "{1}".\n'.format(e,url))预期状态= 301永久移动
您可以访问该页面或使用url检查http://www.redirect-checker.org/index.php以获得正确的终端打印。
返回状态= 200 OK
页面已经被移动,它应该返回上面的301 Moved Permanently,但是它返回一个200。我读取了请求文档并检查了所有参数(allow_redirects=False等)但我不认为这是配置上的错误。
我不明白为什么请求不会看到重定向。
有什么想法吗?
提前谢谢你。
发布于 2020-04-17 00:54:42
默认情况下,Python模块在True中具有allow_redirect参数。我用False测试过它,它给出了你要找的301代码。

注意,在阅读了上面的注释之后: r.history将每个response_code保存在当前保存在r.status_code中的每个response_code之前(只有当您将参数保存在True中时)。
https://stackoverflow.com/questions/61262332
复制相似问题