使用Tor + Privoxy时在Localhost上请求API内容

时间:2018-08-24 20:23:57

标签: python proxy tor privoxy

我正在使用Tor,Privoxy和Python匿名爬网源。 Tor配置为ControlPort 9051,而Privoxy配置为forward-socks5 / localhost:9050 .

我的脚本可以正常工作,除非我请求在同一台计算机上8000上运行的API资源。如果使用代理通过urllib2安装程序访问API,则会收到空字符串响应。如果我使用urllib2的新的非代理实例访问API,则会收到 HTTP错误503:转发失败

我敢肯定,如果我向世界开放8000,我将能够通过代理访问该端口。但是,必须有更好的方法来访问localhost上的资源。很好奇人们如何处理这个问题。

1 个答案:

答案 0 :(得分:0)

我能够通过使用以下打开器来关闭代理并访问内部API:

let iterate1 (f : unit -> seq<int>) =
    for e in f() do printfn "%d" e
let iterate2 (f : unit -> #seq<int>) =
    for e in f() do printfn "%d" e

// Passing a function that takes a list requires a cast.
iterate1 (fun () -> [1] :> seq<int>)

// Passing a function that takes a list to the version that specifies a
// flexible type as the return value is OK as is.
iterate2 (fun () -> [1])

我不确定是否有更好的方法,但是它确实有效。