Fixed by passing 'True'
socks.set_default_proxy(socks.SOCKS5, "109.201.154.195", 1080, True, 'user','pass')
Frage
I'm trying to connect to a SOCKS5 proxy using urllib2 and PySocks. My proxy has a username and password and I use the below code, however I always get a socks.SOCKS5Error: 0x02: Connection not allowed by ruleset message when I'm trying to connect. Would anyone know what I'm doing wrong..?
import socket
import socks
import urllib2
socks.set_default_proxy(socks.SOCKS5, "xx.xx.xx", 8080, 'username','pass')
socket.socket = socks.socksocket
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'}
site = 'http://www.google.com'
req = urllib2.Request(site, headers=hdr)
try:
page = urllib2.urlopen(req)
except urllib2.HTTPError, e:
print e.fp.read()
content = page.read()
print content
Full error: socks.SOCKS5Error: 0x02: Connection not allowed by ruleset
EDIT: to include new error message
Lösung
Fixed by passing 'True'
socks.set_default_proxy(socks.SOCKS5, "109.201.154.195", 1080, True, 'user','pass')