princenyeche/S2C

Login problem

Closed this issue · 9 comments

Hi Prince,

First of all, thanks a lot for the code for transferring attachments from one Jira instance to another.
I am trying to transfer attachments from Server to Datacenter but facing some problem regarding Server Login (Error: Server credentials might be wrong) but I have tried multiple times with correct login details, same error I am getting. May be Jira login module is not working correctly for me.

I am able to login into Server using the below basic login, Could you please release another version of your code which includes the below login, so that it will be useful for all those persons who are facing similar problem.
Thank you so much.

[
from jira import JIRA
jiraOptions = {'server': "http://localhost:8080/"}
jira = JIRA(options=jiraOptions, basic_auth=("user1", "admin"))
for singleIssue in jira.search_issues(jql_str='project = "Test Software Project" and issuetype = Story'):
print('{}: {}:{}'.format(singleIssue.key, singleIssue.fields.summary,
singleIssue.fields.reporter.displayName))
]

Hey @anilkumar23a

I would suggest you add letsencrypt SSL to your localhost instance to get it to work "as is" because the problem here might be that the SSL is not being verified that's why the login fails. I have never tested it on a non HTTPS connection, so I think the problem might be that.

Can you modify the code on the attachment_transfer.py , so it can output the right errors. Change line 118 with the below code then run the request again.

 echo("Please check your server credentials" 
        " as it might be wrong with code: {}, and reason {}".format(check.status_code, check.reason))

This way, you can get a better understanding to the error. Let me know what output is returned. I still believe it has to do with the SSL but the error reason would give a much better answer.

Hi Prince,
got the following error..
///
('Please check your server credentials as it might be wrong with code: 404, '
'and reason ')

Process finished with exit code 0
///

Both Source and Target are having SSL and Data Centers they are.
Credentials are also correct.
Please help me get this resolved.
Thanks.

Hey @anilkumar23a what is your direct URL to your Jira installation?
e.g

https://myurl.servers.com/jira

OR

https://myurl.servers.com

OR is it something else. You can find out by placing that URL on a browser and see if it loads to Jira's login page for your server installation.

As the response code is stating 404, it could be that the URL you're attempting to connecting isn't the right one, based on that error context. Can you check that out?

Hi,

Now I tried by adding word 'jira' to the URL.... ( https://myurl.servers.com/jira )
got the following error.

///
Traceback (most recent call last):
File "D:\S2C-main\attachment_transfer.py", line 114, in
begin()
File "D:\S2C-main\attachment_transfer.py", line 56, in begin
PROJECT.get_attachments_on_projects(attachment_folder=folders,
File "C:\Users\anil\AppData\Local\Programs\Python\Python310\lib\site-packages\jiraone\reporting.py", line 372, in get_attachments_on_projects
result_data = json.loads(get_issue.content)
File "C:\Users\anil\AppData\Local\Programs\Python\Python310\lib\json_init_.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\anil\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\anil\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 3 column 1 (char 4)

Process finished with exit code 1

///

Hey @anilkumar23a
I URL I mentioned was just an example. You should substitute that with your own instance URL and try the instruction I mentioned earlier.

hi,

Yes I tried by adding jira to my company URL itself. :)
and got the above error.
Greetings
Anil

Hey @anilkumar23a
As much as I want to help you here. There's nothing I can do if you've not followed the instructions to the letter.

This error traceback

Traceback (most recent call last):
File "D:\S2C-main\attachment_transfer.py", line 114, in
begin()
File "D:\S2C-main\attachment_transfer.py", line 56, in begin
PROJECT.get_attachments_on_projects(attachment_folder=folders,
File "C:\Users\anil\AppData\Local\Programs\Python\Python310\lib\site-packages\jiraone\reporting.py", line 372, in get_attachments_on_projects
result_data = json.loads(get_issue.content)
File "C:\Users\anil\AppData\Local\Programs\Python\Python310\lib\json_init_.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\anil\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\anil\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 3 column 1 (char 4)

Shows that the JSON object cannot be decoded due to None value. That means it was able to connect and authenticate but now, it seems that you most probably do not have access to any project for the attachment extraction using the JQL search. Ensure that all the project you're searching for is valid. Make sure to alter the JQL query on line 36 of the script. That way, you're querying your own project resource for information.

hi,

Finally it got executed, got the following error, can we remove SSL check, so that it would become executable on any kind of instance.
Thanks.


D:\S2C-main>python attachment_transfer.py
Attachment extraction processing
Attachment extraction completed
File extraction completed. Your file is located at D:\S2C-main\Attachments\attachment_data.csv
Attachment from http://XXXXXXXXXX:8080 downloaded


Copying attachments...
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 1040, in validate_conn
conn.connect()
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 414, in connect
self.sock = ssl_wrap_socket(
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\ssl
.py", line 449, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\ssl
.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 512, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1070, in _create
self.do_handshake()
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1341, in do_handshake
self._sslobj.do_handshake()

requests.exceptions.SSLError: HTTPSConnectionPool(host='XXXXXXXXXX.com', port=443): Max retries exceeded with url: /rest/api/latest/myself (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)')))

That's good. To do that anywhere you see the HTTP method add the argument verify=False to the method e.g.
Line 69 on the script
Line 84 on the script
Line 93 on the script

look = LOGIN.get(endpoint.myself(), verify=False)

fetch = LOGIN.get(attachment, verify=False).content

run = LOGIN.post(endpoint.issue_attachments(keys, query="attachments"), files=payload, verify=False)

Change to above.