【发布时间】:2011-06-27 17:37:58
【问题描述】:
我用ssh -D localhost:5678 me@server.com 打开了一个ssh 隧道,我想在我的python3 应用程序中使用它。
#!/usr/bin/python3.1
# -*- coding:Utf-8 -*-
import urllib.request
proxyhand = urllib.request.ProxyHandler({"socks" : "http://localhost:5678"})
opener = urllib.request.build_opener(proxyhand)
page = opener.open("http://www.mysite.com")
mysite.com 只能从 server.com 上的网络访问(这就是我使用 ssh 隧道的原因)。
它可以不受限制地访问任何其他网站,但对于 mysite.com,我有一个连接超时错误。隧道正常工作,因为我可以使用配置为 as explained here 的 firefox 访问 mysite.com。
谢谢
【问题讨论】:
标签: python proxy urllib ssh-tunnel