0

I'm trying to connect to JIRA using a Python wrapper for the Rest interface and I can't get it to work at all. I've read everything I could find so this is my last resort.

I've tried a lot of stuff including

verify=False

but nothing has worked so far.

The strange thing is that with urllib.request it does work without any SSL cert (it's just some internal cert) but the goal is to use the Python Jira wrapper so it's not really an option...

I've tried Python 3.4 and 2.7... getting desperate...

Any ideas?

The code is very simple:

import requests
r = requests.get('https://jiratest.myurl.com/rest/api/2/serverInfo')
print(r.content)

Error:

C:\Python34\python.exe C:/projects/jirascriptsx/delete_worklogs.py
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 341, in _make_request
    self._validate_conn(conn)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 761, in _validate_conn
    conn.connect()
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connection.py", line 238, in connect
    ssl_version=resolved_ssl_version)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\util\ssl_.py", line 279, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Python34\lib\ssl.py", line 365, in wrap_socket
    _context=self)
  File "C:\Python34\lib\ssl.py", line 583, in __init__
    self.do_handshake()
  File "C:\Python34\lib\ssl.py", line 810, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\requests\adapters.py", line 370, in send
    timeout=timeout
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 574, in urlopen
    raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/projects/jirascriptsx/delete_worklogs.py", line 4, in <module>
    r = requests.get('https://jiratest.uniqa.at/rest/api/2/serverInfo')
  File "C:\Python34\lib\site-packages\requests\api.py", line 69, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Python34\lib\site-packages\requests\api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "C:\Python34\lib\site-packages\requests\sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python34\lib\site-packages\requests\sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python34\lib\site-packages\requests\adapters.py", line 431, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)

Process finished with exit code 1
SebK
  • 487
  • 4
  • 12
  • Have you try to open on port 8080 the url ? – Ali SAID OMAR Jun 22 '15 at 14:32
  • possible duplicate of [Python Requests throwing up SSLError](http://stackoverflow.com/questions/10667960/python-requests-throwing-up-sslerror) – Klaus D. Jun 22 '15 at 14:41
  • What does the port have to do with anything? None of the suggestions from the other question have helped (I had read that one) – SebK Jun 22 '15 at 17:18

2 Answers2

0

There is a problem with our infrastructure which seems to bring out a bug in the requests module where the SSL verification ignore flag doesn't work properly. None of the solutions offered in any of the Stackoverflow posts worked.

As a workaround I'm running the code directly on the server.

SebK
  • 487
  • 4
  • 12
0

If you have certificate file(Certificate.pem) and key file(Key.pem) then we can authenticate like this

cert=/path/to/certificate_file
key_file=/path/to/key_file
url=https://jiratest.myurl.com/rest/api/2/serverInfo

with requests.session() as session:
    session.cert=(cert,key_file)
    session.auth=(username,base64.urlsafe_b64decode(password))
    response=session.get(url) 
if response.status_code == 200:
    json_data = response.json()