简体   繁体   中英

unable to access website with urllib and proxy

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

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

proxyhand = urllib.request.ProxyHandler({"http" : "http://localhost:5678"})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM