我的代码出错了。我每天都运行我的代码并且从来没有任何问题,但是现在,如果我运行它,我有一个Max retries exceeded with url
。如果我从另一台计算机上运行它都是okey并下载我的文件,所以我无法理解发生的事情。
我尝试过这个问题:Python Requests HTTPConnectionPool and Max retries exceeded with url并且也是这样:Python requests max retries exceeded with url但是任何人都无法告诉我如何解决它。
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)'),))
我的代码:
# 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))
答案 0 :(得分:0)
您可能发布的是OS X默认的OpenSSL版本。
如果这是问题,您可以选择以下几种方法:
1)尝试使用python 3(而不是2.7)运行相同的代码。
2)通过从自制软件安装来更新您的OpenSSL版本 - 请点击此处:https://github.com/requests/requests/issues/2022
答案 1 :(得分:0)
从2.7.15版本开始,所有python.org macOS安装程序均随附OpenSSL的内置副本