dify icon indicating copy to clipboard operation
dify copied to clipboard

Vertex AI API Key Incorrrect Padding Error

Open breynded opened this issue 1 year ago • 3 comments

Self Checks

  • [X] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [X] I have searched for existing issues search for existing issues, including closed ones.
  • [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [X] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [X] Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.13

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Trying to add Google Cloud / Vertex AI in Model Provider results in Padding Error message

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

breynded avatar Jul 15 '24 10:07 breynded

Hello @breynded! I'm here to help you with any bugs, questions, or contributions you may have for the repository. Let's work together to resolve any issues you're facing.

To resolve the "Incorrect Padding Error" when trying to add Google Cloud / Vertex AI in the Model Provider on a self-hosted Dify version 0.6.13, ensure that the credentials you are providing are correctly formatted and properly padded. This error typically occurs when the base64 encoded credentials are not correctly padded.

Base64 strings should be padded with = characters to make their length a multiple of 4. You can manually add the necessary padding to your base64 encoded credentials. Here is an example of how you can do this in Python:

import base64

def add_padding(base64_string):
    return base64_string + '=' * (-len(base64_string) % 4)

# Example usage
credentials = "your_base64_encoded_credentials"
padded_credentials = add_padding(credentials)

Ensure that the padded_credentials are then used in the credentials dictionary when calling the validate_credentials method. This should resolve the "Incorrect Padding Error" [1][2][3].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Jul 15 '24 11:07 dosubot[bot]

when will this bug be fixed and merged @dosu

kevinz avatar Jul 22 '24 11:07 kevinz

I updated to dify 0.10.1 and this bug has not been fixed yet !

loudmu avatar Oct 23 '24 15:10 loudmu

Hi. I was having the same issue because I was copying the private key inside the JSON file. I managed to configure the Vertex Model by using these settings:

Project-ID: your-project-id Location: us-east1 Service Account Key: Encode the whole JSON text file to base64 (the file generated in IAM->Service Accounts->Create Service Account->Keys->Add Key->Create New Key-> JSON). You can use Python to do that, or this website for instance.

neyec avatar Nov 11 '24 15:11 neyec