3 回答

TA贡献1827条经验 获得超4个赞
这里发生的事情是itunes服务器拒绝你的连接(你在短时间内从相同的ip地址发送了太多的请求)
使用url超出最大重试次数:/ in / app / adobe-reader / id469337564?mt = 8
错误跟踪是误导性的,它应该是“无法建立连接,因为目标机器主动拒绝它”。
关于Github上的python.requests lib存在一个问题,请在此处查看
要克服这个问题(不是一个问题,因为它会误导调试跟踪),你应该捕获与连接相关的异常,如下所示:
try:
page1 = requests.get(ap)
except requests.exceptions.ConnectionError:
r.status_code = "Connection refused"
解决这个问题的另一种方法是,如果你使用足够的时间间隔向服务器发送请求,这可以通过sleep(timeinsec)python中的函数来实现(不要忘记导入睡眠)
from time import sleep
所有的请求都是很棒的python lib,希望能解决你的问题。

TA贡献1951条经验 获得超3个赞
只需使用requests'功能:
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
session = requests.Session()
retry = Retry(connect=3, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
session.get(url)
这将GET是URL并在3的情况下重试3次requests.exceptions.ConnectionError。backoff_factor将有助于在定期请求配额的情况下在尝试避免再次失败之间应用延迟。
看一看requests.packages.urllib3.util.retry.Retry,它有很多选项来简化重试。

TA贡献1829条经验 获得超7个赞
就这样做,
粘贴以下代码代替page = requests.get(url):
import time
page = ''
while page == '':
try:
page = requests.get(url)
break
except:
print("Connection refused by the server..")
print("Let me sleep for 5 seconds")
print("ZZzzzz...")
time.sleep(5)
print("Was a nice sleep, now let me continue...")
continue
别客气 :)
添加回答
举报