0

I have this error with my code. I run every day my code and never have any problem but now, if I run it I have a Max retries exceeded with url. If I run it from another computer all is okey and download my files so i can't understad what happend. I tried with this question: Python Requests HTTPConnectionPool and Max retries exceeded with url and with this too: Python requests max retries exceeded with url but anyone can't tell my how I can solve it.

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/adapters.py", line 506, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='url', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, u'[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:661)'),))

My code:

# encoding=utf8
# -*- coding: utf-8 -*-
import random
import requests
from requests.auth import HTTPBasicAuth
import sys
import pandas as pd
import datetime
from datetime import date
from dateutil.relativedelta import relativedelta
import os

reload(sys)
sys.setdefaultencoding('utf-8')
number = str(random.random())
url = 'url'

today = date.today()
d = today - relativedelta(months=1)
d2 = today - relativedelta(months=2)

inicio_mes_pasado = date(d.year, d.month, 1).strftime("%d/%m/%Y") # Fecha Inicial
final_mes_pasado = (datetime.date.today().replace(day=1)+datetime.timedelta(days=-1)).strftime("%d/%m/%Y") # Fecha Final

inicio_mes_pasado2 = date(d2.year, d2.month, 1).strftime("%d/%m/%Y") # Fecha Inicial 2 meses antes
final_mes_pasado2 = (date(d.year, d.month, 1) - relativedelta(days=1)).strftime("%d/%m/%Y") # Fecha Final 2 meses antes



cuenta = ['@']

for itemm in cuenta:
    user = '{}'.format(itemm)
    passwd = 'pass'
    login = requests.get(url, auth=HTTPBasicAuth(user, passwd))
    # Espacios
    url_espacios = 'url{}'.format(final_mes_pasado)
    espacios = requests.get(url_espacios, auth=HTTPBasicAuth(user, passwd))
    f = open("Espacios_{}.csv".format(itemm), "w")
    f.write(((((espacios.text.replace('.','')).replace(',','.')).replace('%', '')).replace(';',',')).replace('"',''))
    f.close()
    df = pd.read_csv("Espacios_{}.csv".format(itemm))

2 Answers2

0

It's possible that you're issue is with OS X default OpenSSL version.

If this is the issue, you have a few options:

1) Try running the same code with python 3 (instead of 2.7).

2) Update you're OpenSSL version by installing it from homebrew - see more here: https://github.com/requests/requests/issues/2022

Tom
  • 1,105
  • 8
  • 17
0

As of 2.7.15, all python.org macOS installers ship with a builtin copy of OpenSSL

-- https://www.python.org/downloads/release/python-2715/

denis
  • 21,378
  • 10
  • 65
  • 88