我的代码和异常如下-
# Import libraries
import betfairlightweight
from betfairlightweight import APIClient
import os
# Print the current working directory
print("Current working directory:", os.getcwd())
# Print the contents of the directory
print("Contents of the directory:")
for item in os.listdir("C:\\Program Files (x86)\\xcacerts\\"):
print(item)
# Certificate path for betfair
certs_path = "C:\\Program Files (x86)\\xcacerts\\"
# Betfair login and app key
my_username = "xxxxx"
my_password = "xxxxx"
my_app_key = "xxxxxx"
try:
\# Initialize the Betfair API client
trading = betfairlightweight.APIClient(username=my_username,
password=my_password,
app_key=my_app_key,
certs=certs_path)
# Attempt to login
trading.login()
# Check if login was successful
if trading.session_token:
print("Login successful.")
else:
print("Login failed. Check your credentials.")
except Exception as e:
print(f"An error occurred: {e}")
错误是-
发生错误:无
参数:无
异常:HTTPSConnectionPool(主机='identitysso-cert.betfair.com',端口=443):超过最大重试次数,网址:/api/certlogin(由SSLError(SSLError(524297,'[SSL] PEM lib(_ssl.c)引起) :3900)')))
我尝试过以下方法 -
更新 SSL 库:确保您的 SSL 库是最新的。您可以通过包管理器或升级 Python 本身来更新 SSL 库。
验证SSL证书:检查服务器使用的SSL证书(本例中为identitysso-cert.betfair.com)是否有效且可信。您可以通过在 Web 浏览器中打开 URL 并检查证书详细信息来完成此操作。
我从未使用过 Betfair 轻量级或 Python,所以这只是一个建议。作为身份验证的一部分,您可能缺少“ssoid”吗?