Chris Dye
Chris Dye

Reputation: 1

When trying to verify a cert to link to Betfair API I am receiving an Exception (WinError 267), I can't understand why it would be showing this?

The following is the code I have used and the resuting error -

# Import libraries
import betfairlightweight
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:\\Users\\xx\\OneDrive\\Desktop\\ArbBetfairScripts\\"):
print(item)

# Certificate path for betfair
certs_path = "C:\\Users\\xx\\OneDrive\\Desktop\\ArbBetfairScripts\\BA.crt"

# Betfair login and app key
my_username = "*************"
my_password = "*************"
my_app_key = "*************"

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



runcell(0, 'C:/Users/xx/OneDrive/Desktop/ArbBetfairScripts/BetLogAPI.py')
Current working directory: C:\Users\xx\OneDrive\Desktop\ArbBetfairScripts
Contents of the directory:
BA.crt
BetLogAPI.py
LoginAPI.py
An error occurred: None 
Params: None 
Exception: [WinError 267] The directory name is invalid:             'C:\\Users\\xx\\OneDrive\\Desktop\\ArbBetfairScripts\\BA.crt'

I have tried the following -

Verify Certificate Location:

Check that the BA.crt file is present in the directory: 'C:\Users\xx\OneDrive\Desktop\ArbBetfairScripts'. Confirm that the file name and extension are correct.

Correct Certificate Path:

If the certificate is in a different directory, update the certs_path accordingly. If the certificate is in a subdirectory named certs, for example, set certs_path = "certs/BA.crt".

Ensure Valid Certificate:

Confirm that the certificate file (BA.crt) is a valid SSL certificate. You may open it using a text editor to ensure it contains valid certificate information.

Install Betfairlightweight:

Ensure that the betfairlightweight library is installed in your Python environment.

Upvotes: 0

Views: 99

Answers (0)

Related Questions