# Request Timeout:HTTPConnectionPool(host='jsonplaceholder.typicode.com', port=80): Max retries exceeded with url: /posts123 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000019126226010>, 'Connection to jsonplaceholder.typicode.com timed out. (connect timeout=0.01)')
#coding=utf-8 import requests response = requests.get('http://httpbin.org/redirect/3',allow_redirects=False) print("http status code:",response.status_code) print('redirect url:',response.headers.get('Location')) print(response.text) # http status code: 302 # redirect url: /relative-redirect/2 # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> # <title>Redirecting...</title> # <h1>Redirecting...</h1> # <p>You should be redirected automatically to target URL: <a href="/relative-redirect/2">/relative-redirect/2</a>. If not click the link. # ↑无法正常获取了,因为禁用了自动重定向
# 查看历史重定向链接 response=requests.get('http://httpbin.org/redirect/3') for r in response.history: print('重定向历史链接:',r.url)