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