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

update_topic does not work? #94

Open
fbpsysadm opened this issue Oct 4, 2023 · 1 comment
Open

update_topic does not work? #94

fbpsysadm opened this issue Oct 4, 2023 · 1 comment

Comments

@fbpsysadm
Copy link

python 3.11
pydiscourse latest 1.6.1

from pydiscourse import DiscourseClient

client = DiscourseClient(
  'https://www.mydomain.com',
  api_username='admin',
  api_key='alsdjfaldjfajdfajds;fjalsdf')

# update a post, it works 
post_id = 23232
new_content = "something to change"
client.update_post(post_id, new_content, edit_reason="")

# exception here
topic_url = "https://www.mydomain.com/t/2427.json"
client.update_topic(topic_url, "new title")

exception as below.

>>> client.update_topic(topic_url, "title")
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/urllib3/connection.py", line 203, in _new_conn
    sock = connection.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/urllib3/util/connection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/socket.py", line 962, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/urllib3/connectionpool.py", line 491, in _make_request
    raise new_e
  File "/opt/homebrew/lib/python3.11/site-packages/urllib3/connectionpool.py", line 467, in _make_request
    self._validate_conn(conn)
  File "/opt/homebrew/lib/python3.11/site-packages/urllib3/connectionpool.py", line 1092, in _validate_conn
    conn.connect()
  File "/opt/homebrew/lib/python3.11/site-packages/urllib3/connection.py", line 611, in connect
    self.sock = sock = self._new_conn()
                       ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/urllib3/connection.py", line 210, in _new_conn
    raise NameResolutionError(self.host, self, e) from e
urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPSConnection object at 0x101c527d0>: Failed to resolve 'www.mydomain.comhttps' ([Errno 8] nodename nor servname provided, or not known)

seems, it complains about the server name, but the url is correct. it works fine if call it with request directly as below.

# update the topic title with requests, it works
topic_url = "https://www.mydomain.com/t/2427.json"
headers = {
    'Api-Key': 'asdfasdfasdfasdfadfa',
    'Api-Username': 'admin'
}
payload = {
    'title': "new title"
}
# Send the PUT request to update the topic title
response = requests.put(topic_url, headers=headers, json=payload)
if response.status_code == 200:
    print('Topic title updated successfully.')
@goetzk
Copy link
Collaborator

goetzk commented Oct 5, 2023

I don't have time to debug in detail right now but this line looks like it might hold a clue

urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPSConnection object at 0x101c527d0>: Failed to resolve 'www.mydomain.comhttps' ([Errno 8] nodename nor servname provided, or not known)

Specifically 'www.mydomain.comhttps' appears to have https in the wrong place. I'm not sure how that could happen :|

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

No branches or pull requests

2 participants