用于polipo的鱿鱼式外部重定向器不起作用

时间:2011-03-25 07:27:43

标签: python http proxy

我正在尝试为polipo http代理编写一个简单的squid样式重定向器,如指定的in the documentation

以下是代码:

#!/usr/bin/python

# based on
# http://gofedora.com/how-to-write-custom-redirector-rewritor-plugin-squid-python/

import sys

def modify_url(line):
    l = line.split(" ")
    old_url = l[0]
    new_url = "\n"
    if "experts-exchange" in old_url:
        new_url = "http://127.0.0.1/" + new_url
    return new_url

while True:
    line = sys.stdin.readline().strip()
    new_url = modify_url(line)
    sys.stdout.write(new_url)
    sys.stdout.flush()

使用此重定向器运行polipo并尝试访问http://www.experts-exchange.com/时,出现以下错误:

500 Couldn't test for forbidden URL: Redirector error

实际上,我在尝试访问任何网址时遇到同样的错误,这让我觉得我的重定向代码存在问题。

polipo日志中的输出没有提供更多提示,我只看到:

Redirector returned incomplete reply.

我做错了什么?

编辑:我修复了modify_url()来返回一个值,因为它没有。我仍然遇到同样的错误。

1 个答案:

答案 0 :(得分:1)

该网站(gofedora)提到您需要在modify_url中返回空行或修改后的网址以使其正常工作。如果您手动运行此操作,也会看到错误。您的解决方案是在modify_url的末尾返回new_url。

请注意,您还需要chmod + x以允许您的代理运行脚本。