'Error: Could not identify the intended function with name 'swapExactTokensForTokens'

I'm trying to swap tokens using swapExactTokensForTokens() (Pancakeswap Router function), web3 imported in Python. Here's my code and error below. Please be specific in your answers, as I'm a newbie to coding.

tokenToSpend=$BUSD, tokenToBuy=$CAKE 

Code:

#Calculate minimum amount of tokens to receive

receive = contract.functions.getAmountsOut(amount, [tokenToSpend, tokenToBuy]).call()
minReceived = receive[1] * (9/10)                                                       
receiveReadable = web3.fromWei(minReceived,'ether')                       
print("Minimum tokens to recieve:", str(receiveReadable))

#Trade execution:

pancakeswap2_txn = contract.functions.swapExactTokensForTokens(minReceived, [tokenToSpend,tokenToBuy], sender_address, (int(time.time()) + 1000000)).buildTransaction({   
            'from': sender_address,
            'value': web3.toWei(amount,'ether'), 
            'gasPrice': web3.toWei('5','gwei'),
            'nonce': nonce,
            })

Here's the error msg:

Traceback (most recent call last):
  File "c:/Users/Owner/Documents/BlockchainPy/MyCodes/BuyPancake.py", line 64, in <module>
    pancakeswap2_txn = contract.functions.swapExactTokensForTokens(minReceived, [spend,tokenToBuy], sender_address, (int(time.time()) + 1000000)).buildTransaction({

  File "C:\Users\Owner\Documents\BlockchainPy\lib\site-packages\web3\contract.py",
line 876, in __call__
    clone._set_function_info()
  File "C:\Users\Owner\Documents\BlockchainPy\lib\site-packages\web3\contract.py",
line 881, in _set_function_info
    self.abi = find_matching_fn_abi(
  File "C:\Users\Owner\Documents\BlockchainPy\lib\site-packages\web3\_utils\contracts.py", line 163, in find_matching_fn_abi
    raise ValidationError(message)
web3.exceptions.ValidationError:
Could not identify the intended function with name `swapExactTokensForTokens`, positional argument(s) of type `(<class 'float'>, <class 'list'>, <class 'str'>, <class 'int'>)` and keyword argument(s) of type `{}`.
Found 1 function(s) with the name `swapExactTokensForTokens`: ['swapExactTokensForTokens(uint256,uint256,address[],address,uint256)']
Function invocation failed due to improper number of arguments.


Solution 1:[1]

Try re-copy-and-pasting your Factory or Router ABIs... It seems I found and replaced "MyVariableName" from "WBNB" (or "WETH") in the mentioned ABIs. Got rid of that error after a bit of looking around

Solution 2:[2]

After minReceived you need to supply minAmountOut which is basically slippage. Try 0, that will essentially match the best price and it should work

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 James