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

Problem when importing CasdoorSDK or AsyncCasdoorSDK #67

Closed
ahmad-alkadri opened this issue Sep 7, 2023 · 19 comments · Fixed by #68
Closed

Problem when importing CasdoorSDK or AsyncCasdoorSDK #67

ahmad-alkadri opened this issue Sep 7, 2023 · 19 comments · Fixed by #68
Assignees
Labels
bug Something isn't working

Comments

@ahmad-alkadri
Copy link

Parameters

Keys Values
Python version 3.11.0
Casdoor version 1.16.1
Installation method pip install casdoor
Virtual environment venv

Issue

Cannot import neither CasdoorSDK nor AsyncCasdoorSDK. Followed the guide in README.md, tried both:

from casdoor import CasdoorSDK

and

from casdoor import AsyncCasdoorSDK

And they either return:

Traceback (most recent call last):
  File "$PATH_TO_FOLDER/CasdoorDev/FlaskOnly/app.py", line 2, in <module>
    from casdoor import CasdoorSDK
  File "$PATH_TO_FOLDER/CasdoorDev/FlaskOnly/venv/lib/python3.11/site-packages/casdoor/__init__.py", line 1, in <module>
    from .async_main import AsyncCasdoorSDK  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "$PATH_TO_FOLDER/CasdoorDev/FlaskOnly/venv/lib/python3.11/site-packages/casdoor/async_main.py", line 24, in <module>
    from .user import User
  File "$PATH_TO_FOLDER/CasdoorDev/FlaskOnly/venv/lib/python3.11/site-packages/casdoor/user.py", line 20, in <module>
    from src.casdoor import CasdoorSDK
ModuleNotFoundError: No module named 'src'

for the CasdoorSDK or:

Traceback (most recent call last):
  File "$PATH_TO_FOLDER/CasdoorDev/FlaskOnly/app.py", line 2, in <module>
    from casdoor import AsyncCasdoorSDK
  File "$PATH_TO_FOLDER/CasdoorDev/FlaskOnly/venv/lib/python3.11/site-packages/casdoor/__init__.py", line 1, in <module>
    from .async_main import AsyncCasdoorSDK  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "$PATH_TO_FOLDER/CasdoorDev/FlaskOnly/venv/lib/python3.11/site-packages/casdoor/async_main.py", line 24, in <module>
    from .user import User
  File "$PATH_TO_FOLDER/CasdoorDev/FlaskOnly/venv/lib/python3.11/site-packages/casdoor/user.py", line 20, in <module>
    from src.casdoor import CasdoorSDK
ModuleNotFoundError: No module named 'src'

for the AsyncCasdoorSDK.

At a first glance it seems to me there's some error in the paths of the modules within.

Any help would be appreciated.

@casbin-bot
Copy link

@casbin-bot casbin-bot added the question Further information is requested label Sep 7, 2023
@hsluoyz hsluoyz added bug Something isn't working and removed question Further information is requested labels Sep 7, 2023
@hsluoyz
Copy link
Member

hsluoyz commented Sep 7, 2023

@uestc-wxy

@palp1tate
Copy link
Contributor

palp1tate commented Sep 7, 2023

The problem will be solved soon.Wait for a minute.

@ahmad-alkadri
Copy link
Author

ahmad-alkadri commented Sep 7, 2023

The problem will be solved soon.Wait for a minute.

Thank you @uestc-wxy I appreciate it.


EDIT I don't know if this could help you guys or not, and I'm not 100% sure if this is preferred by you, but to be transparent fully here: I finally managed to make it working by changing all instances of from src.casdoor to from .main.

Details in this commit: ahmad-alkadri@dec84d4

Hope this helps.

@palp1tate
Copy link
Contributor

The problem will be solved soon.Wait for a minute.

Thank you @uestc-wxy I appreciate it.

EDIT I don't know if this could help you guys or not, and I'm not 100% sure if this is preferred by you, but to be transparent fully here: I finally managed to make it working by changing all instances of from src.casdoor to from .main.

Details in this commit: ahmad-alkadri@dec84d4

Hope this helps.

yes,I had made one PR. I fixed it the same way you did.I'm sorry to trouble you

@hsluoyz
Copy link
Member

hsluoyz commented Sep 7, 2023

Fixed by: #68

@hsluoyz hsluoyz closed this as completed Sep 7, 2023
@palp1tate
Copy link
Contributor

casdoor1.16.2 has released. You can use it by pip.

@ahmad-alkadri
Copy link
Author

Tried and tested it; I can confirm it works well for my app.

There's still some problem of the unit tests not working (the ones in the src > tests folder) but I think that's a topic for a different day.

If you guys allow it I can try contribute on it later.

Again, thanks a lot for the very quick response. Really awesome.

@hsluoyz
Copy link
Member

hsluoyz commented Sep 7, 2023

@ahmad-alkadri contribution is welcome, thanks!

@palp1tate
Copy link
Contributor

Tried and tested it; I can confirm it works well for my app.

There's still some problem of the unit tests not working (the ones in the src > tests folder) but I think that's a topic for a different day.

If you guys allow it I can try contribute on it later.

Again, thanks a lot for the very quick response. Really awesome.

In that case, I'd appreciate it. The code for the unit test was written by someone else, and I ran it unsuccessfully, too.If you are committed to solving this problem, thank you again.

@ahmad-alkadri
Copy link
Author

Tried and tested it; I can confirm it works well for my app.
There's still some problem of the unit tests not working (the ones in the src > tests folder) but I think that's a topic for a different day.
If you guys allow it I can try contribute on it later.
Again, thanks a lot for the very quick response. Really awesome.

In that case, I'd appreciate it. The code for the unit test was written by someone else, and I ran it unsuccessfully, too.If you are committed to solving this problem, thank you again.

@uestc-wxy Did you run it unsuccessfully using both the previous and this fixed version of the module too? I tried running both and both returned a lot of errors.

Also if you prefer I'll open a new issue later so we can discuss this.

@palp1tate
Copy link
Contributor

can try contribute on it

Yes,you can open a new issue.

@palp1tate
Copy link
Contributor

Tried and tested it; I can confirm it works well for my app.
There's still some problem of the unit tests not working (the ones in the src > tests folder) but I think that's a topic for a different day.
If you guys allow it I can try contribute on it later.
Again, thanks a lot for the very quick response. Really awesome.

In that case, I'd appreciate it. The code for the unit test was written by someone else, and I ran it unsuccessfully, too.If you are committed to solving this problem, thank you again.

@uestc-wxy Did you run it unsuccessfully using both the previous and this fixed version of the module too? I tried running both and both returned a lot of errors.

Also if you prefer I'll open a new issue later so we can discuss this.

I had made one PR. It fixed the bug that related functions could not be found after the project structure was reorganized.But the code of unit test was written by someone else. Last time I test it,too many errors were found and I had no ideas about how to solve them.If you could try contribute on it ,I can't thank you enough.
My running results are as follows:
image
image

@ahmad-alkadri
Copy link
Author

At a glance, it seems that the target casdoor url doesn't work, and thus no return to our requests were made.

I think it means we should have a self-hosted casdoor up and running for the purpose of the tests.

Let's work on it; I'll start making some commits and open a draft PR so we can go through it bit by bit.

@palp1tate
Copy link
Contributor

At a glance, it seems that the target casdoor url doesn't work, and thus no return to our requests were made.

I think it means we should have a self-hosted casdoor up and running for the purpose of the tests.

Let's work on it; I'll start making some commits and open a draft PR so we can go through it bit by bit.

I'm glad to go through it with you!
Last time I laso changed the target casdoor url, such as http://localhost:8000.The test failed ,too.But it ran faster.Maybe there were some errors in the functions.
My running results are as follows:
image
image

@hsluoyz
Copy link
Member

hsluoyz commented Sep 8, 2023

@ahmad-alkadri @uestc-wxy you don't need to start a Casdoor server, you can use our demo site in CI: https://github.com/casdoor/casdoor#online-demo

If you only do GET operations, use door.casdoor.com

If you also need to Update/Add/Delete, use demo.casdoor.com

@ahmad-alkadri
Copy link
Author

ahmad-alkadri commented Sep 8, 2023

@ahmad-alkadri @uestc-wxy you don't need to start a Casdoor server, you can use our demo site in CI: https://github.com/casdoor/casdoor#online-demo

If you only do GET operations, use door.casdoor.com

If you also need to Update/Add/Delete, use demo.casdoor.com

Thanks @hsluoyz. I'm aware of casdoor's public APIs and I've tested them.
The thing is that for some tests, using the public APIs (door.casdoor.com) work well.

On the other hand, most (I haven't tested all) methods related to getting the oauth token doesn't work.

It doesn't surprise me, for it seems that we'd need the code, username, password, clientid, and all other things related to the casdoor instance, and the way to get them is by replacing the values in the current test file with the ones from our own instance:

class TestOAuth(TestCase):
"""
You should replace the code content below and
the get_sdk() method's content with your own Casdoor
instance and such if you need to. And running these tests successfully
proves that your connection to Casdoor is good-and-working!
"""
# server returned authorization code
code = "6d038ac60d4e1f17e742"
# Casdoor user and password for auth with
# Resource Owner Password Credentials Grant.
# Grant type "Password" must be enabled in Casdoor Application.
username = ""
password = ""
@staticmethod
def get_sdk():
sdk = CasdoorSDK(
endpoint="http://test.casbin.com:8000",
client_id="3267f876b11e7d1cb217",
client_secret="3f0d1f06d28d65309c8f38b505cb9dcfa487754d",
certificate="CasdoorSecret",
org_name="built-in",
application_name="app-built-in",
)
return sdk

Unless casdoor's public APIs have those values that are available for public testing? In that case, could you share them please? Thank you in advance.

@hsluoyz
Copy link
Member

hsluoyz commented Sep 8, 2023

@ahmad-alkadri use real information in demo site, like: https://github.com/casdoor/casdoor-python-vue-sdk-example#configuration , just using this config would be OK

Use admin/123 as username/password

client_secret and certificate content on the demo site are also public to use

@ahmad-alkadri
Copy link
Author

Thanks @hsluoyz. I'll definitely test it out and will keep you guys updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants