Coder Social home page Coder Social logo

Comments (10)

manox avatar manox commented on July 27, 2024 1

Jenkins 2.332.3 and ujenkins 0.3.0

from ujenkins.

manox avatar manox commented on July 27, 2024 1

Thanks, it works when disabling ssl checks.

from ujenkins.

pbelskiy avatar pbelskiy commented on July 27, 2024

Hello! Thanks for bugreport, which version of Jenkins and package are you using?

from ujenkins.

pbelskiy avatar pbelskiy commented on July 27, 2024

@manox I've installed same versions using docker, but all is okay. Could you please add print to 152 line of
/usr/local/lib/python3.9/dist-packages/ujenkins/adapters/sync.py and write here output?

response = self._http_request('GET', CRUMB_ISSUER_URL)
print(response)

And to ``/usr/local/lib/python3.9/dist-packages/ujenkins/core.py` in 43 line

print(response.headers)
if 'application/json' in response.headers.get('Content-Type', ''):

It seems somehow Jenkins returns header without json and it's unpacked from str to json.

Where is your Jenkins server, maybe some proxy is using?

from ujenkins.

manox avatar manox commented on July 27, 2024

First of all, thanks for the help. The Jenkins server is local on the network and I access it via a local IP. I used a Jenkins image that I believe has a reverse proxy built in.
Here is the output with the prints.

{'Date': 'Wed, 08 Jun 2022 09:37:41 GMT', 'Server': 'Apache', 'Location': 'https://192.168.178.73/crumbIssuer/api/json', 'Content-Length': '251', 'Keep-Alive': 'timeout=5, max=100', 'Connection': 'Keep-Alive', 'Content-Type': 'text/html; charset=iso-8859-1'}
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://192.168.178.73/crumbIssuer/api/json">here</a>.</p>
</body></html>

Traceback (most recent call last):
  File "/root/test.py", line 8, in <module>
    example()
  File "/root/test.py", line 5, in example
    version = client.system.get_version()
  File "/usr/local/lib/python3.9/dist-packages/ujenkins/endpoints/system.py", line 40, in get_version
    return self.jenkins._request('GET', '/', callback=callback)
  File "/usr/local/lib/python3.9/dist-packages/ujenkins/adapters/sync.py", line 174, in _request
    self.crumb = self._get_crumb()
  File "/usr/local/lib/python3.9/dist-packages/ujenkins/adapters/sync.py", line 153, in _get_crumb
    self.crumb = {response['crumbRequestField']: response['crumb']}
TypeError: string indices must be integers

Edit: I just noticed that it works when attaching the port (8080) to the server address. Problem is therefore solved. Thanks!

from ujenkins.

pbelskiy avatar pbelskiy commented on July 27, 2024

@manox anyway there is bug in package, it's because of redirect is not processed, could you share please your reverse proxy config of apache?

from ujenkins.

manox avatar manox commented on July 27, 2024

OK, sure.

root@jenkins ~# cat /etc/apache2/sites-enabled/jenkins.conf 
ServerName localhost

<VirtualHost *:80>
    UseCanonicalName Off
    RewriteEngine on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on
    UseCanonicalName Off
    ProxyRequests Off
    ProxyPreserveHost On
    AllowEncodedSlashes NoDecode
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPass / http://localhost:8080/ nocanon
    ProxyPassReverse / http://localhost:8080/
    RequestHeader set X-Forwarded-Proto "https"
    RequestHeader set X-Forwarded-Port "443"
</VirtualHost>

from ujenkins.

pbelskiy avatar pbelskiy commented on July 27, 2024

@manox fixed in https://github.com/pbelskiy/ujenkins/releases/tag/v0.3.3 please check it

from ujenkins.

manox avatar manox commented on July 27, 2024

At first it was not possible to install the package from the sources. I had to add the encoding in ujenkins/setup.py in line 18.

with open('README.rst', encoding='utf-8') as readme_file:

Now when I try to reach the server without specifying the port the following happens. Since it is only a local test setup I have not installed an SSl certificate.

Traceback (most recent call last):
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\urllib3\connectionpool.py", line 1040, in _validate_conn
    conn.connect()
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\urllib3\connection.py", line 414, in connect
    self.sock = ssl_wrap_socket(
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\urllib3\util\ssl_.py", line 453, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\urllib3\util\ssl_.py", line 495, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock)
  File "C:\Users\marka\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "C:\Users\marka\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1071, in _create
    self.do_handshake()
  File "C:\Users\marka\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1342, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\requests\adapters.py", line 440, in send
    resp = conn.urlopen(
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='192.168.178.73', port=443): Max retries exceeded with url: /crumbIssuer/api/json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:997)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\marka\jenkins_agent_manager\manager.py", line 14, in <module>
    connect()
  File "c:\Users\marka\jenkins_agent_manager\manager.py", line 5, in connect
    version = client.system.get_version()
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\ujenkins\endpoints\system.py", line 40, in get_version
    return self.jenkins._request('GET', '/', callback=callback)
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\ujenkins\adapters\sync.py", line 172, in _request
    self.crumb = self._get_crumb()
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\ujenkins\adapters\sync.py", line 150, in _get_crumb
    response = self._http_request('GET', CRUMB_ISSUER_URL)
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\ujenkins\adapters\sync.py", line 134, in _http_request
    response = self.session.request(
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\requests\sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\requests\sessions.py", line 667, in send
    history = [resp for resp in gen]
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\requests\sessions.py", line 667, in <listcomp>
    history = [resp for resp in gen]
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\requests\sessions.py", line 237, in resolve_redirects
    resp = self.send(
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\requests\sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\marka\jenkins_agent_manager\.venv\lib\site-packages\requests\adapters.py", line 517, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='192.168.178.73', port=443): Max retries exceeded with url: /crumbIssuer/api/json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:997)')))

from ujenkins.

pbelskiy avatar pbelskiy commented on July 27, 2024

Thanks for another issue. About your problem, you can disable ssl check using Jenkins(..., verify=False)

from ujenkins.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.