api4jenkins icon indicating copy to clipboard operation
api4jenkins copied to clipboard

Unable to create agent/node

Open NicoR45 opened this issue 4 months ago • 3 comments

Hi, I'm trying to create an agent.

. Version
Jenkins 2.426.3
Python 3.12.7
api4jenkins 2.0.3

My code is:

from api4jenkins import Jenkins

j = Jenkins(url_base, auth=(MyUser, MyPassword), timeout=10)

j.nodes.create(r"{'nodeDescription': '', 'numExecutors': 1, 'remoteFS': '/home/jenkins', 'labelString': '', 'mode': 'NORMAL', 'retentionStrategy': {'stapler-class': 'hudson.slaves.RetentionStrategy$Always'}, 'nodeProperties': {'stapler-class-bag': 'true'}, 'launcher': {'stapler-class': 'hudson.slaves.JNLPLauncher'}}'")

Returned traceback :

Traceback (most recent call last):
  File "b:\MyPath\python\test.py", line 58, in <module>
    j.nodes.create(r"{'nodeDescription': '', 'numExecutors': 1, 'remoteFS': '/home/jenkins', 'labelString': '', 'mode': 'NORMAL', 'retentionStrategy': {'stapler-class': 'hudson.slaves.RetentionStrategy$Always'}, 'nodeProperties': {'stapler-class-bag': 'true'}, 'launcher': {'stapler-class': 'hudson.slaves.JNLPLauncher'}}'")
  File "C:\Users\MyUser\bin\python-3.12.7\inst\Lib\site-packages\api4jenkins\node.py", line 84, in create
    self.handle_req('POST', 'doCreateItem',
  File "C:\Users\MyUser\bin\python-3.12.7\inst\Lib\site-packages\api4jenkins\item.py", line 98, in handle_req
    return self._request(method, self.url + entry, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\MyUser\bin\python-3.12.7\inst\Lib\site-packages\httpx\_client.py", line 837, in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\MyUser\bin\python-3.12.7\inst\Lib\site-packages\httpx\_client.py", line 926, in send
    response = self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\MyUser\bin\python-3.12.7\inst\Lib\site-packages\httpx\_client.py", line 954, in _send_handling_auth
    response = self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\MyUser\bin\python-3.12.7\inst\Lib\site-packages\httpx\_client.py", line 1011, in _send_handling_redirects
    raise exc
  File "C:\Users\MyUser\bin\python-3.12.7\inst\Lib\site-packages\httpx\_client.py", line 994, in _send_handling_redirects
    hook(response)
  File "C:\Users\MyUser\bin\python-3.12.7\inst\Lib\site-packages\api4jenkins\http.py", line 29, in check_response
    raise BadRequestError(f'400 {response.headers["X-Error"]}')
api4jenkins.exceptions.BadRequestError: 400 ':' est un caractère dangereux #translation --> "is a dangerous character"

What have I done wrong? What character ':' does the error message refer to?

NicoR45 avatar Oct 16 '24 13:10 NicoR45