Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

悦跑圈抓取数据时错误,遇到错误:Max retries exceeded with url错误。 #664

Open
Xiaoshizi1024 opened this issue Apr 21, 2024 · 7 comments

Comments

@Xiaoshizi1024
Copy link

在vscode中运行,具体出现的反馈代码如下:

C:\Users\Administrator> & C:/Users/Administrator/AppData/Local/Programs/Python/Python38/python.exe d:/JoyRundateto/running_page-master/run_page/joyrun_sync.py 18XXXXX  验证码  --with-gpx
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 776, in urlopen
    self._prepare_proxy(conn)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 1045, in _prepare_proxy
    conn.connect()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 619, in connect
    self.sock = sock = self._connect_tls_proxy(self.host, sock)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 675, in _connect_tls_proxy
    sock_and_verified = _ssl_wrap_socket_and_match_hostname(
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 782, in _ssl_wrap_socket_and_match_hostname
    ssl_sock = ssl_wrap_socket(
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\ssl_.py", line 470, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\ssl_.py", line 514, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1040, in _create
    self.do_handshake()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
OSError: [Errno 0] Error

The above exception was the direct cause of the following exception:

urllib3.exceptions.ProxyError: ('Unable to connect to proxy', OSError(0, 'Error'))

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 486, in send
    resp = conn.urlopen(
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 844, in urlopen
    retries = retries.increment(
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.thejoyrun.com', port=443): Max retries exceeded with url: //user/login/phonecode?phoneNumber=188XXXXX&identifyingCode=验证码&signature=C914F1CE592643369EE52D84EF7CC8D6&timestamp=1713698195 (Caused by ProxyError('Unable to connect to proxy', OSError(0, 'Error')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:/JoyRundateto/running_page-master/run_page/joyrun_sync.py", line 368, in <module>
    j.login_by_phone()
  File "d:/JoyRundateto/running_page-master/run_page/joyrun_sync.py", line 142, in login_by_phone
    r = self.session.get(
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 513, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='api.thejoyrun.com', port=443): Max retries exceeded with url: //user/login/phonecode?phoneNumber=手机号&identifyingCode=820481&signature=C914F1CE592643369EE52D84EF7CC8D6&timestamp=1713698195 (Caused by ProxyError('Unable to connect to proxy', OSError(0, 'Error')))

问ai,它的解释是:

从您提供的错误信息来看,似乎您的 Python 脚本在尝试通过 HTTPS 连接到 api.thejoyrun.com 时无法成功通过代理服务器。更具体地说,脚本在 SSL 握手过程中无法建立与代理服务器的连接,并且在尝试多次重试后,最终引发了 MaxRetryError 异常。

解决这个问题可能需要以下几个步骤:

检查代理服务器设置:
确认您的代理服务器设置是否正确。包括代理服务器地址、端口和任何身份认证信息。

检查网络连接:
确认您的机器可以连接到代理服务器以及目标 api.thejoyrun.com。您可以通过 ping 命令或者尝试在浏览器中访问来检查。

检查 SSL/TLS 支持:
确保您的代理服务器支持 SSL/TLS 连接。您可以尝试访问其他 HTTPS 网站以验证此事。

检查 Python 和库版本:
确保您的 Python 版本和所有相关库(特别是 requests 和 urllib3)都是最新的,或者至少是还在维护的版本。旧版本的库可能不支持某些加密协议或包含已知的错误。

禁用或配置 TLS/SSL 验证:
如果您信任代理服务器并了解潜在的安全风险,您可以尝试在 requests 调用中禁用 SSL 验证(仅作为临时测试手段,不推荐在生产环境中使用):

python
response = requests.get('https://example.com', verify=False)
或者正确配置 SSL 上下文以适应代理的要求。

查看更详细的日志:
您可以使用 logging 模块查看更详细的日志,了解问题发生的具体环节。

检查代码中代理使用方式:
检查 joyrun_sync.py 脚本中的代理使用方式,确保代理的配置是正确的。

联系代理服务提供商:
如果问题依然存在,您可以考虑联系您的代理服务提供商,可能是代理服务侧有问题或者有特定的连接要求。

最后,请再次检查您是否需要通过代理服务器进行连接。如果不是必须的,您可以尝试直接连接到目标服务器而不经过代理。如果需要通过代理服务器,确保您的代理设置是正确的,并且代理服务器处于工作状态且可接受来自您的机器的连接。


我进行的尝试

1. ping尝试

关闭我个人的代理,然后ping api.thejoyrun.com,是通的。
image

并且用以及等待5、6分钟的验证码,在悦跑圈上通过验证码登录,竟然一下子就登录上去了。

2. 检查python 和库版本

主要的requests 2.31.0 基本上是最新版本,urllib3 2.2.1 也是2个月前更新的;但是requests相关的requests-oauthlib 、requests-toolbelt 看着版本好低,尝试更新

requests-oauthlib 1.3.1 >> 2.0.0
requests-toolbelt 1.0.0 >> 1.0.0

更新过再次尝试,还是出现同样的错误代码。

查看python相关库,所有内容

C:\Users\Administrator>pip list
Package               Version
--------------------- --------------
aiofiles              23.2.1
annotated-types       0.6.0
appdirs               1.4.4
arrow                 1.3.0
beautifulsoup4        4.12.3
bitstruct             8.11.1
certifi               2024.2.2
cffi                  1.16.0
charset-normalizer    3.3.2
cloudscraper          1.2.58
colour                0.1.5
et-xmlfile            1.1.0
eviltransform         0.1.1
fit-tool              0.9.13
future                1.0.0
garmin-fit-sdk        21.133.0
garth                 0.4.45
geographiclib         2.0
geopy                 2.4.1
gpxpy                 1.4.2
greenlet              3.0.3
h11                   0.9.0
h3                    3.7.7
haversine             2.8.0
httpcore              0.11.1
httpx                 0.15.5
idna                  3.7
jdcal                 1.4.1
lxml                  4.9.4
markdown-it-py        3.0.0
mdurl                 0.1.2
numpy                 1.26.4
oauthlib              3.2.2
openpyxl              2.5.12
pip                   24.0
polyline              2.0.2
pycparser             2.22
pycryptodome          3.20.0
pydantic              2.7.0
pydantic_core         2.18.1
Pygments              2.17.2
pyparsing             3.1.2
python-dateutil       2.9.0.post0
pytz                  2024.1
PyYAML                6.0.1
requests              2.31.0
requests-oauthlib     1.3.1
requests-toolbelt     1.0.0
rfc3986               1.5.0
rich                  13.7.1
s2sphere              0.2.5
setuptools            69.5.1
six                   1.16.0
sniffio               1.3.1
soupsieve             2.5
SQLAlchemy            2.0.29
stravalib             0.10.4
stravaweblib          0.0.8
svgwrite              1.4.3
tcxreader             0.4.10
tenacity              8.2.3
timezonefinder        6.5.0
types-python-dateutil 2.9.0.20240316
typing_extensions     4.11.0
tzdata                2024.1
tzlocal               5.2
units                 0.7
urllib3               2.2.1

请问怎么处理这个错误吗?

@yihong0618
Copy link
Owner

换个网络环境试试

@Xiaoshizi1024
Copy link
Author

换个网络环境试试

换到手机热点上尝试,还是出现同样的错误。
image

@ben-29
Copy link
Sponsor Collaborator

ben-29 commented Apr 21, 2024

The above exception was the direct cause of the following exception:

urllib3.exceptions.ProxyError: ('Unable to connect to proxy', OSError(0, 'Error'))

检查一下代理配置是否正确, cmd 执行:

echo %HTTP_PROXY%
echo %HTTPS_PROXY%

@Xiaoshizi1024
Copy link
Author

The above exception was the direct cause of the following exception:
urllib3.exceptions.ProxyError: ('Unable to connect to proxy', OSError(0, 'Error'))

检查一下代理配置是否正确, cmd 执行:

echo %HTTP_PROXY%
echo %HTTPS_PROXY%

这意思是没有代理吗?

image

@Xiaoshizi1024
Copy link
Author

刚才尝试将Keep的数据转成gpx文件,一下就成功了。。。

还是要放弃悦跑圈这个平台,太封闭了,原始数据记录导出来就放弃,不用他了。

@yihong0618
Copy link
Owner

理论上悦跑圈也行,你换台电脑试试

@ben-29
Copy link
Sponsor Collaborator

ben-29 commented Apr 21, 2024

The above exception was the direct cause of the following exception:
urllib3.exceptions.ProxyError: ('Unable to connect to proxy', OSError(0, 'Error'))

检查一下代理配置是否正确, cmd 执行:

echo %HTTP_PROXY%
echo %HTTPS_PROXY%

这意思是没有代理吗?

image

你这应该是 power shell, 先输 cmd

cmd
echo %HTTP_PROXY%
echo %HTTPS_PROXY%

如果不对,问问ai怎么修改成你真实的代理

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants