验证证书连接Betfair API时遇SSL PEM库错误求助
连接Betfair API证书验证异常问题
尝试通过证书验证连接Betfair API时触发异常,无法明确原因,相关代码、报错信息及已尝试操作如下:
代码示例
# 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}")
(注:已修正代码缩进问题,路径字符串添加转义反斜杠避免解析错误)
报错信息
An error occurred: None
Params: None
Exception: HTTPSConnectionPool(host='identitysso-cert.betfair.com', port=443): Max retries exceeded with url: /api/certlogin (Caused by SSLError(SSLError(524297, '[SSL] PEM lib (_ssl.c:3900)')))
已尝试操作
- 更新SSL库:确保SSL库为最新版本,通过包管理器或升级Python完成
- 验证SSL证书:检查服务器(identitysso-cert.betfair.com)使用的SSL证书是否有效且受信任,通过浏览器打开该URL查看证书详情
内容的提问来源于stack exchange,提问作者Chris Dye
相关产品推荐
相关产品推荐

