Question

I've opened a ssh tunnel with ssh -D localhost:5678 me@server.com and I want to use it in my python3 application.

#!/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")

Where mysite.com can only be accessed from the network on server.com (that's why I use a ssh tunnel).

It works to access any other website with no limitations but for mysite.com I have a connection timed out error. The tunnel works as I can access mysite.com using firefox configured as explained here.

Thank you

Was it helpful?

Solution

Should you be using http as the protocol, not socks? Thus:

proxyhand = urllib.request.ProxyHandler({"http" : "http://localhost:5678"})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top