Portal account owner must have a role Exception in Salesforce

There are two possibilities for this issue:

1. Running user for creating Account, Contact and User for Experience Cloud site access doesn't have a Role.

To fix this issue, assign a Role to the running user.

Reference Article:

2. Creating User for an Experience Cloud site and the account owner of the Contact is not having a Role.

To fix this issue, assign a Role to the Account owner of the Contact record from which the User is getting created.