1
resposta

Erro na interação com o labdados

Meu código: url = 'https://labdados.com/produtos' response = requests.get(url)

Resultado[ERRO]:

SSLError Traceback (most recent call last) File ~\AppData\Roaming\Python\Python39\site-packages\urllib3\connectionpool.py:700, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw) 699 if is_new_proxy_conn and http_tunnel_required: --> 700 self._prepare_proxy(conn) 702 # Make the request on the httplib connection object.

... SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1129)

During handling of the above exception, another exception occurred:

MaxRetryError Traceback (most recent call last) File ~\AppData\Roaming\Python\Python39\site-packages\requests\adapters.py:489, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies) ... File ~\AppData\Roaming\Python\Python39\site-packages\urllib3\connectionpool.py:785, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw) 783 e = ProtocolError("Connection aborted.", e) --> 785 retries = retries.increment( 786 method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2] 787 ) 788 retries.sleep()

File ~\AppData\Roaming\Python\Python39\site-packages\urllib3\util\retry.py:592, in Retry.increment(self, method, url, response, error, _pool, _stacktrace) 591 if new_retry.is_exhausted(): --> 592 raise MaxRetryError(_pool, url, error or ResponseError(cause)) 594 log.debug("Incremented Retry for (url='%s'): %r", url, new_retry)

MaxRetryError: HTTPSConnectionPool(host='labdados.com', port=443): Max retries exceeded with url: /produtos (Caused by ProxyError('Your proxy appears to only use HTTP and not HTTPS, try changing your proxy URL to be HTTP. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#https-proxy-error-http-proxy', SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1129)'))))

During handling of the above exception, another exception occurred:

ProxyError Traceback (most recent call last) Cell In[14], line 2 1 url = 'https://labdados.com/produtos' ----> 2 response = requests.get(url)

File ~\AppData\Roaming\Python\Python39\site-packages\requests\api.py:73, in get(url, params, **kwargs) 62 def get(url, params=None, **kwargs): 63 r"""Sends a GET request. 64 65 :param url: URL for the new :class:Request object. (...) 70 :rtype: requests.Response 71 """ ---> 73 return request("get", url, params=params, **kwargs)

File ~\AppData\Roaming\Python\Python39\site-packages\requests\api.py:59, in request(method, url, **kwargs) 55 # By using the 'with' statement we are sure the session is closed, thus we 56 # avoid leaving sockets open which can trigger a ResourceWarning in some 57 # cases, and look like a memory leak in others. 58 with sessions.Session() as session: ---> 59 return session.request(method=method, url=url, **kwargs)

File ~\AppData\Roaming\Python\Python39\site-packages\requests\sessions.py:587, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 582 send_kwargs = { 583 "timeout": timeout, 584 "allow_redirects": allow_redirects, 585 } 586 send_kwargs.update(settings) --> 587 resp = self.send(prep, **send_kwargs) 589 return resp

File ~\AppData\Roaming\Python\Python39\site-packages\requests\sessions.py:701, in Session.send(self, request, **kwargs) 698 start = preferred_clock() 700 # Send the request --> 701 r = adapter.send(request, **kwargs) 703 # Total elapsed time of the request (approximately) 704 elapsed = preferred_clock() - start

File ~\AppData\Roaming\Python\Python39\site-packages\requests\adapters.py:559, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies) 556 raise RetryError(e, request=request) 558 if isinstance(e.reason, _ProxyError): --> 559 raise ProxyError(e, request=request) 561 if isinstance(e.reason, _SSLError): 562 # This branch is for urllib3 v1.22 and later. 563 raise SSLError(e, request=request)

ProxyError: HTTPSConnectionPool(host='labdados.com', port=443): Max retries exceeded with url: /produtos (Caused by ProxyError('Your proxy appears to only use HTTP and not HTTPS, try changing your proxy URL to be HTTP. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#https-proxy-error-http-proxy', SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1129)'))))

1 resposta

Olá, Marina!

O erro SSLError: WRONG_VERSION_NUMBER é geralmente é causado quando o cliente e o servidor não conseguem estabelecer uma conexão segura.

É capaz que você esteja atrás de um proxy que está interferindo na sua conexão SSL. Se for esse o caso, você pode tentar configurar o proxy no seu código. Aqui está um exemplo de como você pode fazer isso:

import requests

proxies = {
  'http': 'http://10.10.1.10:3128',
  'https': 'http://10.10.1.10:1080',
}

url = 'https://labdados.com/produtos'
response = requests.get(url, proxies=proxies)

Mas para continuar, você precisaria substituir 10.10.1.10:3128 e 10.10.1.10:1080 pelo endereço e porta do seu proxy, ok?

Se outra dúvida surgir, estamos disponíveis.

Abraços e bons estudos!

Caso este post tenha lhe ajudado, por favor, marcar como solucionado ✓.