0

I have a python script set up to send attachments to our JIRA server. I've noticed that it seems to fail on all zip files. Has anyone experienced this before? Below is the error that it always returns. Any other files that it encounters send just fine.

Traceback (most recent call last):
  File "C:\opt\python\Python35\lib\site-packages\requests\adapters.py", line 370, in send
    timeout=timeout
  File "C:\opt\python\Python35\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 609, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\opt\python\Python35\lib\site-packages\requests\packages\urllib3\util\retry.py", line 245, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "C:\opt\python\Python35\lib\site-packages\requests\packages\urllib3\packages\six.py", line 309, in reraise
    raise value.with_traceback(tb)
  File "C:\opt\python\Python35\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 559, in urlopen
    body=body, headers=headers)
  File "C:\opt\python\Python35\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 353, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "C:\opt\python\Python35\lib\http\client.py", line 1083, in request
    self._send_request(method, url, body, headers)
  File "C:\opt\python\Python35\lib\http\client.py", line 1128, in _send_request
    self.endheaders(body)
  File "C:\opt\python\Python35\lib\http\client.py", line 1079, in endheaders
    self._send_output(message_body)
  File "C:\opt\python\Python35\lib\http\client.py", line 913, in _send_output
    self.send(message_body)
  File "C:\opt\python\Python35\lib\http\client.py", line 882, in send
    self.sock.sendall(datablock)
requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

Edit - Here is the code, per request. The code works fine as long as it is not trying to send a zip file. I did also notice that even if I try to send a zip attachment via cURL, it fails the same. So, I do not believe it is a problem with the code...?

from jira import JIRA
import os
import datetime as dt
import random
import time
import glob

jira=JIRA(basic_auth=('user','password'),options={'server':'http://jira.server.com'})
now=dt.datetime.now()
ago=now-dt.timedelta(minutes=120)

for root,dirs,files in os.walk('c:\\opt\\attachments\\'):
  for fname in files:
    found=0;
    randomNum=str(random.randrange(0,101,2))
    path=os.path.join(root,fname)
    st=os.stat(path)
    mtime=dt.datetime.fromtimestamp(st.st_ctime)
    if mtime>ago:
      for afile in glob.iglob("c:\\opt\\attachments\\processed\\*"+fname):
        print("found file: "+afile);
        found=1;

      if found==0:
        print('%s modified %s'%(path,mtime))
        fileParts=fname.split("_")
        fileName=fileParts[1]
        jiraID=fileParts[0]
        try:
          jira.add_attachment(jiraID,path,fname)
        except:
          time.sleep(2)
          os.rename(path,"c:\\opt\\attachments\\FAILED\\"+randomNum+"_"+fname)
          time.sleep(2)
          continue
        time.sleep(2)
        os.rename(path,"c:\\opt\\attachments\\processed\\"+randomNum+"_"+fname)
        time.sleep(2)
      else:
        time.sleep(2)
        os.rename(path,"c:\\opt\\attachments\\ignored\\exists_"+randomNum+"_"+fname)
    else:
      print('ignore: %s modified %s'%(path,mtime))
      os.rename(path,"c:\\opt\\attachments\\ignored\\tooOld_"+randomNum+"_"+fname)
      time.sleep(2)
  break
w3bguy
  • 2,215
  • 1
  • 19
  • 34
  • 1
    Please reduce your code to the shortest possible complete program that still demonstrates the error. Then copy-paste that entire, short, complete program into your question. See http://stackoverflow.com/help/mcve for more info. – Robᵩ Nov 02 '15 at 20:45

1 Answers1

0

A quick google search of the error code produces a couple results of timeouts. This could be caused by a couple different things, the problem that is similar to your problem is due to file size causing the server to terminate the connection due to the long upload time.

Things to try: Make sure you have the latest version of the jira software on your server so that the bug fixes are applied, try uploading a smaller zip file manually and see if it works. If none of that works try reporting a bug on jira's site.

File size ticket: https://jira.atlassian.com/plugins/servlet/mobile#issue/JRA-9037/comment/49681

Fr3dBear
  • 16
  • 3
  • Yeah, Google was my first stop. It's not a size issue. I tried with a 10kb file, vs a 1mb non-zipped file. The non-zipped worked fine, the zipped did not. Yeah, guess I'll go to the JIRA site. – w3bguy Nov 03 '15 at 21:45