如何从ssh创建代理以连接请求和sshtunnel

时间:2016-03-24 05:45:38

标签: python ssh python-requests

这是我的代码

from sshtunnel import SSHTunnelForwarder
import requests
server = SSHTunnelForwarder(
    (MY_IP, 22),
    ssh_username=MY_USERNAME,
    ssh_password=MY_PASSWORD,
    remote_bind_address=('127.0.0.1', 5555)
)

server.start()

print(server.local_bind_port)
# work with `SECRET SERVICE` through `server.local_bind_port`.
print requests.get("http://127.0.0.1:"+str(server.local_bind_port))
server.stop()

我得到错误

2016-03-24 12:35:32,864 | ERROR   | Secsh channel 0 open FAILED: : Connect failed
2016-03-24 12:35:32,866 | ERROR   | In #1 <-- ('127.0.0.1', 50448) to ('127.0.0.1', 5555) failed: ChannelException(2, 'Connect failed')

如何使其成为代理

0 个答案:

没有答案