Python url请求超过最大重试次数

Python url请求超过最大重试次数,python,python-requests,Python,Python Requests,我正在尝试从web上刮取此页面,我使用的代码如下: page = get("https://www.uobgroup.com/online-rates/gold-and-silver-prices.page") 我在运行此代码时遇到此错误: Traceback (most recent call last): File "/Users/lakesh/WebScraping/Gold.py", line 46, in <module>

我正在尝试从web上刮取此页面,我使用的代码如下:

page = get("https://www.uobgroup.com/online-rates/gold-and-silver-prices.page")
我在运行此代码时遇到此错误:

Traceback (most recent call last):
  File "/Users/lakesh/WebScraping/Gold.py", line 46, in <module>
    page = get("https://www.uobgroup.com/online-rates/gold-and-silver-prices.page")
  File "/Library/Python/2.7/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/adapters.py", line 511, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.uobgroup.com', port=443): Max retries exceeded with url: /online-rates/gold-and-silver-prices.page (Caused by SSLError(SSLError(1, u'[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)'),))
这也不行。需要一些指导

完整代码:

from requests import get
import requests
from requests.exceptions import RequestException
from contextlib import closing
from bs4 import BeautifulSoup
from collections import defaultdict
import json

requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'DES-CBC3-SHA'
page = get("https://www.uobgroup.com/online-rates/gold-and-silver-prices.page")
html = BeautifulSoup(page.content, 'html.parser')
result = defaultdict(list)
last_table = html.find_all('table')[-1]

我添加了
verify=False
选项,还取出了设置密码的行。一旦我这样做了,你的代码在Python 3中为我工作……有时。它只工作过一次,然后一段时间似乎不起作用。我的猜测是,该站点正在限制访问速率,可能是基于它看到的代理签名,试图限制bot访问。当它工作时,我打印了上一张表,下面是我得到的:

<table class="responsive-table-rates table table-striped table-bordered" id="nova-funds-list-table">
<tbody>
<tr>
<td style="background-color: #002265; text-align: center; color: #ffffff;">DESCRIPTION</td>
<td style="background-color: #002265; text-align: center; color: #ffffff;">CURRENCY</td>
<td style="background-color: #002265; text-align: center; color: #ffffff;">UNIT</td>
<td style="background-color: #002265; text-align: center; color: #ffffff;">BANK SELLS</td>
<td style="background-color: #002265; text-align: center; color: #ffffff;">BANK BUYS</td>
<td style="text-align: left; display: none;"> </td>
<td style="text-align: left; display: none;"> </td>
</tr>
</tbody>
</table>

我在Mac电脑上。也许你没有,而且你机器上的证书链和我机器上的不同,所以你不能尽我所能。但是,我想让您知道,您的代码确实适用于我,只要将
verify=False
设置为
verify
False
。小心,这不会检查证书的有效性。在其他程序中,它可能使您的计算机暴露给黑客

请使用以下代码重试:

page = get("https://www.uobgroup.com/online-rates/gold-and-silver-prices.page", verify=False)

您可能会从requests.packages.urllib3.util.ssl\u.DEFAULT\u CIPHERS='DES-CBC3-SHA'中得到一些指导,但出现了以下错误:名称'requests'未定义。我从stacktrace猜测您的代码可能有一个来自requests import get的
。如果是这种情况,请添加一个
导入请求
。仍然无法获取数据。我也发布了我的代码。我暗示的指导是,该网站可能正在做一些它接受的密码奇怪的事情<代码>curl-v…
显示接受DHE-RSA-AES256-GCM-SHA384连接的站点。试试看,我不知道发生了什么事。在我的Mac电脑上,它在Python 2.716和3.7.3下运行良好。我跑得很高,谢拉我正在运行bs4-0.0.1。我的代码与您的代码相同,只是我在
get
调用的末尾添加了
verify=False
。-它现在一直在为我运行。你最近试过吗?也许是网站的问题。哦,等等。。我的代码不一样。我注释掉了
requests.packages.urllib3.util.ssl\u.DEFAULT\u密码='DES-CBC3-SHA'
行我会发布我的代码…不会,它不会再工作了。我觉得这个网站有些不对劲又开始工作了。它的工作时间和不工作时间是非常随机的我不认为是访问次数的问题。我刚刚连续成功运行了8次,第9次尝试失败。哦…顺便说一句…我没有得到身份验证或SSL错误。我总是很满足。我只是有时候会返回一个错误页面,或者看起来是这样。
from requests import get
from bs4 import BeautifulSoup
from collections import defaultdict

page = get("https://www.uobgroup.com/online-rates/gold-and-silver-prices.page", verify=False)
html = BeautifulSoup(page.content, 'html.parser')
result = defaultdict(list)
last_table = html.find_all('table')[-1]
print(last_table)
page = get("https://www.uobgroup.com/online-rates/gold-and-silver-prices.page", verify=False)