gpt4 book ai didi

python - 重定向 url 只是打印到屏幕 - python

转载 作者:太空宇宙 更新时间:2023-11-03 15:21:30 26 4
gpt4 key购买 nike

我写了一个简单的 python 脚本来在点击广告后重定向 url。
与广告关联的 url 是 http://server.example.com/redirect.py

redirect.py 的代码如下所示:

import cgi
import cgitb

cgitb.enable()
print('Content-Type: text/html\n\n')
print('Location: http://www.finalurl.com')

但是,当点击广告时,并没有将请求重定向到 www.finalurl.com,最终的 url 只是简单地显示在浏览器窗口中。非常感谢所有帮助。

请注意,redirect.py 脚本位于 /public_html/cgi-bin/ 文件夹中,并且该脚本具有 711 权限。另外,目标 url 不会总是相同的 url,它基于数据库查询。该代码被简单地省略了。

我也试过包括:print ("Status: 301 Moved")

最佳答案

'\n\n' 是 http header 标记的结尾,请改用:

print 'Status: 301 Moved Permanently'
print 'Location: http://www.finalurl.com'
print 'Content-Type: text/html'
print # end of header
... # short html with the url

关于python - 重定向 url 只是打印到屏幕 - python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14088763/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com