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

User class not working #6

Open
Will-Zhao0 opened this issue Mar 6, 2023 · 8 comments
Open

User class not working #6

Will-Zhao0 opened this issue Mar 6, 2023 · 8 comments

Comments

@Will-Zhao0
Copy link

Hello,

I tried the example in your doc to get information of all users, but it didn't work. The errors are as follows:

Traceback (most recent call last):
File "/home/admin/trial2.py", line 62, in
client.lists()
File "/home/admin/.local/lib/python3.9/site-packages/synapse_admin/user.py", line 117, in lists
resp = self.connection.request(
File "/home/admin/.local/lib/python3.9/site-packages/synapse_admin/base.py", line 626, in request
return request(url, **kwargs)
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_client.py", line 1045, in get
return self.request(
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_client.py", line 821, in request
return self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_client.py", line 908, in send
response = self._send_handling_auth(
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_client.py", line 936, in _send_handling_auth
response = self._send_handling_redirects(
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_client.py", line 973, in _send_handling_redirects
response = self._send_single_request(request)
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_client.py", line 1009, in _send_single_request
response = transport.handle_request(request)
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 218, in handle_request
resp = self._pool.handle_request(req)
File "/usr/lib/python3.9/contextlib.py", line 135, in exit
self.gen.throw(type, value, traceback)
File "/home/admin/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ConnectError: [Errno -2] Name or service not known

@KnugiHK
Copy link
Owner

KnugiHK commented Mar 6, 2023

What's your synapse server version? And please provide information from your api.cfg file as much as possible.

@Will-Zhao0
Copy link
Author

The synapse version is 1.76.0, I see the package is only compatible with version <=1.70, but I'm only trying a basic function.

Also I'm new to this, I didn't use a api.cfg file in the process.

Thank you

@Will-Zhao0
Copy link
Author

Btw, for a side question, I'm using ansible playbook to deploy the synapse, so the server lives in a docker container. And all my current admin api calls have to be made after I enter the docker environment. So is there really no way to use python to make admin api calls in my case?

@KnugiHK
Copy link
Owner

KnugiHK commented Mar 6, 2023

The synapse version is 1.76.0, I see the package is only compatible with version <=1.70, but I'm only trying a basic function.

Usually, the compatible version means only (modification of) APIs introduced on or before that version are supported in this wrapper. So, it should be fine for your case.

Also I'm new to this, I didn't use a api.cfg file in the process.

If you are not using api.cfg, I assume you pass the host and account information to the class directly. Could you paste the arguments passed with redaction?

So is there really no way to use python to make admin api calls in my case?

Admin APIs reside on /_synapse/admin/, which is the same server as /_matrix/. Therefore, as long as your users can reach /_matrix/ (the regular chatting operation) and the reverse proxy in your deployment does not block /_synapse/admin/, you should be able to do API calls outside the container.

@Will-Zhao0
Copy link
Author

Absolutely!
Two lines as follows:

client = synapse_admin.User(server_addr="https://matrix.*******.org/", server_port=8008, access_token=params["access_token"], server_protocol="https://")  
client.lists()

@KnugiHK
Copy link
Owner

KnugiHK commented Mar 7, 2023

Does the problem happen all the time or just occasionally? Also, please try the following:

import requests
r = requests.get(
    "https://matrix.*******.org:8008/_synapse"
    "/admin/v2/users?from=0&limit=100&guests="
    "true&deactivated=false&dir=f",
    headers={
        "Authorization": f"Bearer {params['access_token']}",
        "User-Agent": f"matrix-synpase-admin-python/test"
    }
)
print(r.json())

Does it print out a list of users correctly?

@Will-Zhao0
Copy link
Author

The program hangs, I have to kill it with keyboard.
So I guess there is something wrong with forwarding admin api when I set up the synapse.
I'm using ansible, do you happen to know what I might have missed to make admin apis reachable from outside the docker container?

Anyway really appreciated!

@KnugiHK
Copy link
Owner

KnugiHK commented Mar 7, 2023

I have no idea for now, but I will try to deploy a Synapse instance through ansible to see what's the problem.

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

2 participants