在验证证书以连接Betfair API时,我收到一个异常(见正文),我不明白为何会出现这个?

0 投票
1 回答
25 浏览
提问于 2025-04-14 16:15

我的代码和出现的错误如下 -

# 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}")

错误信息是 -

发生了一个错误:没有参数
参数:没有
异常:HTTPS连接池(主机='identitysso-cert.betfair.com',端口=443):最大重试次数超过,网址:/api/certlogin(由SSLError引起(SSLError(524297, '[SSL] PEM库 (_ssl.c:3900)')))

我尝试过以下方法 -

更新SSL库:确保你的SSL库是最新的。你可以通过包管理器更新SSL库,或者直接升级Python。

验证SSL证书:检查服务器使用的SSL证书(在这个例子中是identitysso-cert.betfair.com)是否有效且可信。你可以通过在网页浏览器中打开这个网址,查看证书的详细信息来确认。

1 个回答

0

我从来没有用过Betfair lightweight或者Python,所以这只是个建议。你可能在认证的时候缺少了一个'ssoid'?

撰写回答