langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
45.11k stars 6.33k forks source link

When I try to integrate Github, I get an Internal Server Error. #7550

Closed tar-xzvff closed 6 days ago

tar-xzvff commented 3 weeks ago

Self Checks

Dify version

0.7.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

git clone https://github.com/langgenius/dify.git -b 0.7.1
cd dify/docker
cp .env.example .env
sudo docker compose up -d

After launching Dify, create an administrator account and log in.

Settings -> ACCOUNT -> Integrations Click Connect. スクリーンショット 2024-08-23 0 56 03

It jumps to http:///console/api/oauth/login/github, but an Internal Server Error is displayed.

http:///console/api/oauth/login/github {"message": "Internal Server Error", "code": "unknown"}

The logs are as follows.

$ sudo docker logs -f
api-1         | 2024-08-22 16:00:19,454.454 ERROR [Dummy-10] [app.py:838] - Exception on /console/api/oauth/login/github [GET]
api-1         | Traceback (most recent call last):
api-1         |   File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
api-1         |     rv = self.dispatch_request()
api-1         |   File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
api-1         |     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
api-1         |   File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 489, in wrapper
api-1         |     resp = resource(*args, **kwargs)
api-1         |   File "/app/api/.venv/lib/python3.10/site-packages/flask/views.py", line 110, in view
api-1         |     return current_app.ensure_sync(self.dispatch_request)(**kwargs)  # type: ignore[no-any-return]
api-1         |   File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 604, in dispatch_request
api-1         |     resp = meth(*args, **kwargs)
api-1         |   File "/app/api/controllers/console/auth/oauth.py", line 48, in get
api-1         |     print(vars(oauth_provider))
api-1         | TypeError: vars() argument must have __dict__ attribute
nginx-1       | ***.***.***.*** - - [22/Aug/2024:16:00:19 +0000] "GET /console/api/oauth/login/github HTTP/1.1" 500 56 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "-"

✔️ Expected Behavior

Github integration is available.

❌ Actual Behavior

Github integration is not available.

dosubot[bot] commented 3 weeks ago

@tar-xzvff Greetings! I'm here to assist you with any bugs, questions, or contributions while you await a human maintainer. Let's work together to resolve this issue.

The "Internal Server Error" you're encountering when trying to integrate GitHub in Dify version 0.7.1 using Docker is due to an issue with the vars() function in the oauth.py controller. The error message indicates that the vars() function is being called on an object that does not have a __dict__ attribute.

To resolve this issue, you need to modify the get method in the OAuthLogin class to avoid using vars() on an object that doesn't support it. Here's the corrected implementation:

class OAuthLogin(Resource):
    def get(self, provider: str):
        OAUTH_PROVIDERS = get_oauth_providers()
        with current_app.app_context():
            oauth_provider = OAUTH_PROVIDERS.get(provider)
            if oauth_provider:
                print(oauth_provider.__dict__)
        if not oauth_provider:
            return {'error': 'Invalid provider'}, 400

        auth_url = oauth_provider.get_authorization_url()
        return redirect(auth_url)

Replace the print(vars(oauth_provider)) line with print(oauth_provider.__dict__) to correctly access the attributes of the oauth_provider object.

Additionally, ensure that the Ollama service is accessible from the Docker container by replacing localhost with host.docker.internal in the service URL:

http://host.docker.internal:11434

Update your Docker configuration accordingly:

# Example configuration in docker-compose.yaml
services:
  api:
    environment:
      - SERVICE_API_URL=http://host.docker.internal:11434

This should resolve the connection issue and make the service accessible from the Docker container [1][2].

To continue talking to Dosu, mention @dosu.

JOduMonT commented 1 week ago

from what I understand

it seems they are finally working on it and that issue is old. here you have the solution; but since it is not in english they ignored it in any case you could identify the variables here


Mini HowTo

in your Google Cloud Platform you must create an OAuth which Authorized redirect URIs an URL like this: https://_mydify.mydomain.com_/console/api/oauth/authorize/google after that you will received your GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET which you will add into your .env

### Google
- GOOGLE_CLIENT_ID="Google Client ID"
- GOOGLE_CLIENT_SECRET="Google Client Secret"

remark: the "" are not mandatory

then you will have to restart your dify stack

since you only change .env and not docker-compose.yml it is preferable to do down and up.

docker compose down
docker compose up -d

At the end;

you do understand that it is to authenticate user via Google service and not to access your files in your Google Drive right ?