jenkins-webapi icon indicating copy to clipboard operation
jenkins-webapi copied to clipboard

HTTP 405 when using an HTTP URL for an HTTPS-only server

Open SolalPirelli opened this issue 7 years ago • 0 comments

First, thanks for the excellent library, it's rare to see a lib with clear examples and a full API doc.

Minor bug: When connecting using an HTTP URL to a Jenkins server that forces HTTPS, requests that should be POST-ed seem to be converted to GET instead, so they fail.

Workaround, obviously, is to use the HTTPS URL in the first place.

Trace example (server URL is http://jenkins.example.org/jenkins):

DEBUG:urllib3.connectionpool:http://jenkins.example.org:80 "POST /jenkins/createItem?from=job1&name=job2&mode=copy HTTP/1.1" 301 392
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): jenkins.example.org
header: Date header: Server header: Location header: Content-Length header: Keep-Alive header: Connection header: Content-Type send: b'GET /jenkins/createItem?from=job1&name=job2&mode=copy HTTP/1.1\r\nHost: jenkins.example.org\r\nAccept: */*\r\nUser-Agent: python-requests/2.18.4\r\nConnection: keep-alive\r\nAccept-Encoding: gzip, d
eflate\r\nAuthorization: Basic REMOVED\r\n\r\n'
reply: 'HTTP/1.1 405 Method Not Allowed\r\n'
DEBUG:urllib3.connectionpool:https://jenkins.example.org:443 "GET /jenkins/createItem?from=job1&name=job2&mode=copy HTTP/1.1" 405 198
header: Date header: Server header: X-Content-Type-Options header: Allow header: Content-Type header: Content-Length header: Keep-Alive header: Connection Traceback (most recen
t call last):
  File "./manage.py", line 31, in <module>
    args.command.execute(config, args)
  File "/mnt/d/sweng-scripts/swengmgmt/commands.py", line 143, in execute
    jenkins.clone_job(args.template, job_name)
  File "/mnt/d/sweng-scripts/swengmgmt/jenkins.py", line 11, in clone_job
    self._client.job_copy(job_name, clone_name)
  File "/usr/local/lib/python3.4/dist-packages/jenkins.py", line 718, in job_copy
    return Job.copy(source, dest, self.server)
  File "/usr/local/lib/python3.4/dist-packages/jenkins.py", line 228, in copy
    res = server.post('createItem', params=params, headers=headers)
  File "/usr/local/lib/python3.4/dist-packages/jenkins.py", line 542, in post
    throw and res.raise_for_status()
  File "/usr/local/lib/python3.4/dist-packages/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 405 Client Error: Method Not Allowed for url: https://jenkins.example.org/jenkins/createItem?from=job1&name=job2&mode=copy

SolalPirelli avatar Oct 01 '17 06:10 SolalPirelli