My code and the exception are as follows -
# 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}")
The error is -
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)')))
I have tried the following -
Update SSL Library: Ensure that your SSL library is up to date. You can update your SSL library through your package manager or by upgrading Python itself.
Verify SSL Certificate: Check if the SSL certificate used by the server (identitysso-cert.betfair.com in this case) is valid and trusted. You can do this by opening the URL in a web browser and inspecting the certificate details.
I haver never used Betfair lightweight or Python so this is just a suggestion. It may be you are missing an 'ssoid' as part of your authentication?