Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github connector: No module named 'jwt' #1949

Open
fraimondo opened this issue Oct 10, 2022 · 8 comments
Open

Github connector: No module named 'jwt' #1949

fraimondo opened this issue Oct 10, 2022 · 8 comments

Comments

@fraimondo
Copy link

Description

Please include a summary of the issue.

Just starting with opsdroid to create a github/matrix skill (linking github and matrix), having some functionality like what the github bot did to slack.

Problem is I get an error with the JWT module when starting opsdroid, namely a missing dependency not installed in the virtual environment.

Steps to Reproduce

Please also include relevant information and steps to reproduce the bug/issue.

virtualenv -p python3 opsdroid
source opsdroid/bin/activate
pip install opsdroid[common]

Then create a configuration.yaml file like this:

welcome-message: true
web:
  host: "127.0.0.1"
  port: 8080
connectors:
  github:
    # required
    app_id: 123456
skills:
  hello: {}

opsdroid start will result in this:

[10/10/22 16:01:26] INFO     ========================================                                     logging.py:161
                    INFO     Started opsdroid v0.28.0.                                                    logging.py:162
                    INFO     ========================================                                       utils.py:134
                    INFO     You can customise your opsdroid by modifying your configuration.yaml.          utils.py:135
                    INFO     Read more at: http://opsdroid.readthedocs.io/#configuration                    utils.py:140
                    INFO     Watch the Get Started Videos at: http://bit.ly/2fnC0Fh                         utils.py:143
                    INFO     Install Opsdroid Desktop at:                                                   utils.py:144
                             https://github.com/opsdroid/opsdroid-desktop/releases                                      
                    INFO     ========================================                                       utils.py:150
                    WARNING  No databases in configuration. This will cause skills which store things in   loader.py:359
                             memory to lose data when opsdroid is restarted.                                            
                    ERROR    The following exception was raised while importing connector                  loader.py:112
                             opsdroid.connector.github                                                                  
                    ERROR    No module named 'jwt'                                                         loader.py:117
                    ERROR    Failed to load connector: opsdroid.connector.github.                          loader.py:124
                    ERROR    Module github failed to import.                                               loader.py:495
                    CRITICAL All connectors failed to load.                                                  core.py:137
                    INFO     Exiting application with return code 1

Expected Functionality

Explain what should happen.

Opsdroid should start

Experienced Functionality

Explain what happened instead(Please include the debug log).

Versions

  • Opsdroid version: v0.28.0.
  • Python version: Python 3.8.10
  • OS/Docker version: Ubuntu 20.04.5 LTS

Configuration File

Please include your version of the configuration file below.

welcome-message: true
web:
  host: "127.0.0.1"
  port: 8080
connectors:
  github:
    # required
    app_id: 123456
skills:
  hello: {}

Additional Details

Any other details you wish to include such as screenshots, console messages, etc.

I tried solving the issue by installing jwt or PyJWT (and providing the right github settings), but:

Installing jwt with pip gives en error:

AttributeError: module 'jwt' has no attribute 'encode'

Installing PyJWT gives another error:

AttributeError: 'str' object has no attribute 'decode'
@FabioRosado
Copy link
Member

Hello @fraimondo thank you for raising this issue.

Just to be sure, do you get the same error if you install everything pip install opsdroid[all] ? If so, perhaps the GitHub library isn't adding the jwt package, we can fix that by adding it to our requirements for now (would this be something you would be happy to contribute?)

@fraimondo
Copy link
Author

Yes, even with opsdroid[all].

I temporarily solved it locally by installing PyJWT and then removing the decode("utf-8") call here:

installation_access_token = jwt.encode(
payload, private_key, algorithm="RS256"
).decode("utf-8")

But is this the proper way?

@FabioRosado
Copy link
Member

Hello @fraimondo apologies for the delay in getting back to you. Does it mean we don't need to decode the token anymore?

If you have bandwidth it would be good to add github to the list of connectors and PyJWT to the dependencies, similar to what we do for other connectors here

# connectors

@fraimondo
Copy link
Author

Indeed this is the solution.

I am a bit overwhelmed right now, but I can give it a try at a PR as soon as I find a few minutes free. It should not be a big issue to do it.

@gereltuya
Copy link

Hello @fraimondo, this issue does not come up when installing with pip install opsdroid[all]. Also, the decoding AttributeError was fixed with the last commit to fix #1954 I believe.

@fraimondo
Copy link
Author

It might be the case that PyJWT gets installed as a dependency of a dependency. In my case, it was not installed even with all.

Regarding the decode, I guess #1954 fixes that issue.

@FabioRosado
Copy link
Member

@fraimondo Are you using the latest main or the latest version available in Pypi? If I'm not mistaken we haven't released the fix in #1954 🤔

@fraimondo
Copy link
Author

I'm not using it. It's just that I saw the diff in #1954 and it's exactly what I did to fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants