casdoor / casdoor-python-sdk

Python client SDK for Casdoor
https://pypi.org/project/casdoor
Apache License 2.0
32 stars 33 forks source link

Problem when importing CasdoorSDK or AsyncCasdoorSDK #67

Closed ahmad-alkadri closed 10 months ago

ahmad-alkadri commented 10 months ago

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 commented 10 months ago

@seriouszyx @ComradeProgrammer @Resulte

hsluoyz commented 10 months ago

@uestc-wxy

palp1tate commented 10 months ago

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

ahmad-alkadri commented 10 months ago

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: https://github.com/ahmad-alkadri/casdoor-python-sdk/commit/dec84d40ff8611ae3c1f5fac59ecbe7577b78284

Hope this helps.

palp1tate commented 10 months ago

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 commented 10 months ago

Fixed by: https://github.com/casdoor/casdoor-python-sdk/pull/68

palp1tate commented 10 months ago

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

ahmad-alkadri commented 10 months ago

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 commented 10 months ago

@ahmad-alkadri contribution is welcome, thanks!

palp1tate commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

can try contribute on it

Yes,you can open a new issue.

palp1tate commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

@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 commented 10 months ago

@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:

https://github.com/casdoor/casdoor-python-sdk/blob/a2ec1f5015d939e2ee9e295246d0abe8f6e8bdc9/src/tests/test_oauth.py#L23-L50

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 commented 10 months ago

@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 commented 10 months ago

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