urllib.request
ile açmak ve okumak istiyorum ama bir SSL hatası alıyorum . Gayet iyi bu kodla http.client
kullanarak sayfayı açıp okuyabilir:Python 3.2'de http.client ile bir HTTPS web sayfasını açabilir ve okuyabilirim, ancak urllib.request aynı sayfayı açmakta başarısız oluyor
import http.client
conn = http.client.HTTPSConnection('www.yande.re')
conn.request('GET', 'https://yande.re/')
resp = conn.getresponse()
data = resp.read()
Ancak urllib.request
kullanarak aşağıdaki kod başarısız: ssl.SSLError: [Errno 1] _ssl.c:392: error:1411809D:SSL routines:SSL_CHECK_SERVERHELLO_TLSEXT:tls invalid ecpointformat list
:
import urllib.request
opener = urllib.request.build_opener()
resp = opener.open('https://yande.re/')
data = resp.read()
Bana şu hatayı veriyor. Sayfayı neden HTTPSConnection ile açabilirim, opener.open değil? Düzenleme
:
import http.client
conn = http.client.HTTPSConnection('www.yande.re')
conn.request('GET', 'https://yande.re/')
ve: İşte senin iki örneklerde veren konak kaynaklanmaktadır benim OpenSSL sürümü ve sorun https://yande.re/
>>> import ssl; ssl.OPENSSL_VERSION
'OpenSSL 1.0.0a 1 Jun 2010'
>>> import urllib.request
>>> urllib.request.urlopen('https://yande.re/')
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
urllib.request.urlopen('https://yande.re/')
File "C:\Python32\lib\urllib\request.py", line 138, in urlopen
return opener.open(url, data, timeout)
File "C:\Python32\lib\urllib\request.py", line 369, in open
response = self._open(req, data)
File "C:\Python32\lib\urllib\request.py", line 387, in _open
'_open', req)
File "C:\Python32\lib\urllib\request.py", line 347, in _call_chain
result = func(*args)
File "C:\Python32\lib\urllib\request.py", line 1171, in https_open
context=self._context, check_hostname=self._check_hostname)
File "C:\Python32\lib\urllib\request.py", line 1138, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 1] _ssl.c:392: error:1411809D:SSL routines:SSL_CHECK_SERVERHELLO_TLSEXT:tls invalid ecpointformat list>
>>>
Import ssl öğesinin yapış yapışını yapıştırabilir misiniz? ssl.OPENSSL_VERSION' ve urllib.request.urlopen ('https://yande.re/') ' –
FWIW sonucu, muhtemelen hata ayıklama için bir veri noktasıdır. Eşdeğer Python 2.7.x kodu (aşağıda gösterilmiştir) iyi çalışır: import urllib2 req = urllib2.Request ('https://yande.re') resp = urllib2.urlopen (req) resp.read() – sateesh
http.client için kod yanlıştır . Şunları yapabilirsiniz: 'conn.request ('GET', '/')' – jfs