Python 3.2: urllib, SSL and TOR over socket: error with fileno function

I have an error while trying to connect to https via socksipy with the code below.

I followed an example here: using tor as a SOCKS5 proxy with python urllib2 or mechanize

Or this one: Python urllib over TOR?

Edit: this code works when I use HTTP, but not with HTTPS

I imported socks from the Python Socksipy module.

Here is the code:

import socks import socket #This function has no DNS resolve #it need to use the real ip adress to connect instead of www.google.fr def create_connection_fixed_dns_leak(address, timeout=None, source_address=None): sock = socks.socksocket() sock.connect(address) return sock # MUST BE SET BEFORE IMPORTING URLLIB socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050) # patch the socket module socket.socket = socks.socksocket socket.create_connection = create_connection_fixed_dns_leak # END MUST BE SET BEFORE IMPORTING URLLIB import urllib.request import urllib.error def getURL(pUrl, headers = {}, pNbMaxRetry = 12): req = urllib.request.Request( pUrl ) for headerKey, headerValue in headers: req.add_header( headerKey, headerValue ) resp = urllib.request.urlopen(req) return resp 

Call Method:

 googleAdr = "https://173.194.65.94" pageSocket = getURL( googleAdr ) pageHtml = pageSocket.read() pageSocket.close() page = BeautifulSoup( pageHtml ) print(" Page calendar :" + page .prettify() ) 

Here is the error:

 File "/home/turf/connectSafe.py", line 101, in getURL resp = urllib.request.urlopen(req) File "/usr/lib/python3.2/urllib/request.py", line 139, in urlopen return opener.open(url, data, timeout) File "/usr/lib/python3.2/urllib/request.py", line 370, in open response = self._open(req, data) File "/usr/lib/python3.2/urllib/request.py", line 388, in _open '_open', req) File "/usr/lib/python3.2/urllib/request.py", line 348, in _call_chain result = func(*args) File "/usr/lib/python3.2/urllib/request.py", line 1176, in https_open context=self._context, check_hostname=self._check_hostname) File "/usr/lib/python3.2/urllib/request.py", line 1140, in do_open h.request(req.get_method(), req.selector, req.data, headers) File "/usr/lib/python3.2/http/client.py", line 970, in request self._send_request(method, url, body, headers) File "/usr/lib/python3.2/http/client.py", line 1008, in _send_request self.endheaders(body) File "/usr/lib/python3.2/http/client.py", line 966, in endheaders self._send_output(message_body) File "/usr/lib/python3.2/http/client.py", line 811, in _send_output self.send(msg) File "/usr/lib/python3.2/http/client.py", line 749, in send self.connect() File "/usr/lib/python3.2/http/client.py", line 1111, in connect server_hostname=server_hostname) File "/usr/lib/python3.2/ssl.py", line 189, in wrap_socket _context=self) File "/usr/lib/python3.2/ssl.py", line 243, in __init__ fileno=sock.fileno() TypeError: __init__() got an unexpected keyword argument 'fileno' 

Do you have any ideas? even bad? Thank you very much!

+2
python ssl sockets urllib tor
Oct 14 '14 at 8:48
source share

No one has answered this question yet.

See similar questions:

16
Python urllib over tor?
13
How to redirect urllib requests over a TOR network?
6
Using SocksiPy with SSL
four
using tor as a SOCKS5 proxy with python urllib2 or to mechanize

or similar:

215
urllib and "SSL: CERTIFICATE_VERIFY_FAILED" Error
8
How to handle urllib timeout in Python 3?
one
urllib.request does not work on urlopen unicode strings
one
I get an error when trying to open a website url using Python 3.1, urllib & json: an operation was attempted for something that is not a socket
0
Posting data using urllib without SSL certificate verification
0
MacOS High OSierra 10.13.6, Python3.7, GeocoderServiceError: [SSL: CERTIFICATE_VERIFY_FAILED]
0
Python loads images with mutable variables
0
Error loading image using "urllib.request.urlretrieve" in Python
-2
The stream tensor importing mnist / read_data_sets (from the stream tensor .contrib.learn.python.learn.datasets.mnist) is deprecated /



All Articles