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永久移动
您可以访问页面或使用网址检查http://www.redirect-checker.org/index.php以获得正确的终端打印。
返回状态 = 200 OK
页面已移动,它应该返回上面的301 Moved Permanently
,但是它返回200。我阅读了请求文档并检查了所有参数(allow_redirects = False等),但我不认为这是配置错误。
我很困惑为什么请求无法看到重定向。
有什么想法吗?
谢谢。