python将URL代理传递给另一个

时间:2019-02-13 09:50:55

标签: python proxy

我打算实现一个用于处理请求的httpserver,并且我希望该请求传递给代理后面的其他网址,到目前为止,我已经收到了这段代码。

enter code here
import requests
import http.server
import socketserver


url = 'http://live.impresa.pt/live/sic/sic540p.m3u8'

proxies = {

    'https': 'http://80.211.204.126:443'
}
r = requests.get(url,proxies=proxies)



 class myHandler(http.server.SimpleHTTPRequestHandler):
  def do_GET(self):
    if self.path == '/sic':
        self.send_response(307)
        new_path = r.url
        self.send_header('Location', new_path)
        self.end_headers()

port = 9999
Handler = myHandler
webserver = socketserver.TCPServer(("10.0.0.110",port),Handler)
print ("Python web server ok")
webserver.serve_forever()

当我尝试访问10.0.0.110:9999/sic时,URL没有传递到代理服务器并且直接发送,我该如何更改此请求以使代理服务器发出请求?

0 个答案:

没有答案