英文:
r.history returning an empty list [python]
问题
Here is the code in main.py:
import requests
URL = 'localhost:80'
if 'http' not in URL: URL = 'http://' + URL
r = requests.get(URL)
for resp in r.history:
print(r.url)
Here is the code in webserver.py:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return '<script>location.href = "https://youtube.com"</script>'
if __name__=='__main__':
app.run('0.0.0.0', 80)
r.history returns an empty list when I run main.py.
英文:
Here is the code in main.py
import requests
URL = 'localhost:80'
if 'http' not in URL: URL = 'http://'+ URL
r = requests.get(URL)
for resp in r.history:
print(r.url)
Here is the code in webserver.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return '<script>location.href = "https://youtube.com"</script>'
if __name__=='__main__':
app.run('0.0.0.0', 80)
r.history returns an empty list when I run main.py
答案1
得分: 0
If you wanna get the redicrection url:
app.py
from flask import Flask, redirect
app = Flask(__name__)
@app.route('/')
def index():
return redirect('https://python.org')
if __name__=='__main__':
app.run('0.0.0.0', 80)
req.py
import requests
URL = 'localhost:80'
r = requests.get("http://localhost:80", allow_redirects=True)
print(r.url)
If you wanna get the history of the request
import requests
URL = 'localhost:80'
r = requests.get("http://localhost:80", allow_redirects=True)
print(r.history)
英文:
If you wanna get the redicrection url:
app.py
from flask import Flask, redirect
app = Flask(__name__)
@app.route('/')
def index():
return redirect('https://python.org')
if __name__=='__main__':
app.run('0.0.0.0', 80)
req.py
import requests
URL = 'localhost:80'
r = requests.get("http://localhost:80", allow_redirects=True)
print(r.url)
If you wanna get the history of the request
import requests
URL = 'localhost:80'
r = requests.get("http://localhost:80", allow_redirects=True)
print(r.history)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论