【问题标题】:how to pull url and pass variable to python 3's http.server如何提取 url 并将变量传递给 python 3 的 http.server
【发布时间】:2017-05-04 09:02:05
【问题描述】:

我的 google-fu 让我失望了,可能是因为太晚了。

鉴于下面的代码,我需要获取 domain.tld/ 之后的所有内容并对其进行解析。然后它将针对数据库运行(在示例中我使用的是 dict,但实际上我将调用 mysql,这会改变它吗?)

然后,它将提供带有该 url 的重定向标头。

from http.server import BaseHTTPRequestHandler, HTTPServer

class HTTPServer_RequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(301)
        self.send_header('Location', url)
        self.end_headers()
        return

array["stuff"] = "http://google.com"
array["thing"] = "http://yahoo.com"
url = array[page]

server_address = ('0.0.0.0', 80)
httpd = HTTPServer(server_address, HTTPServer_RequestHandler)
httpd.serve_forever()

【问题讨论】:

    标签: python-3.x simplehttpserver


    【解决方案1】:

    可能有点晚了,但是根据documentationself.path应该返回你服务器位置之后的url

    【讨论】:

      猜你喜欢
      • 2018-05-17
      • 1970-01-01
      • 1970-01-01
      • 2012-10-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-23
      • 2011-02-17
      相关资源
      最近更新 更多