JIRA Python无法发送Zip文件

时间:2015-11-02 20:40:04

标签: python rest jira python-jira

我设置了一个python脚本来将附件发送到我们的JIRA服务器。我注意到它似乎在所有zip文件上都失败了。有谁之前经历过这个吗?以下是它总是返回的错误。它遇到的任何其他文件发送都很好。

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))

编辑 - 这是每个请求的代码。只要不尝试发送zip文件,代码就可以正常工作。我也注意到,即使我尝试通过cURL发送zip附件,它也会失败。所以,我不认为这是代码的问题......?

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

1 个答案:

答案 0 :(得分:0)

快速谷歌搜索错误代码会产生一些超时结果。这可能是由几个不同的问题引起的,与您的问题类似的问题是由于文件大小导致服务器因上传时间过长而终止连接。

要尝试的事项:确保您的服务器上安装了最新版本的jira软件,以便修复错误,尝试手动上传较小的zip文件并查看其是否有效。如果这些都不起作用,请尝试报告jira网站上的错误。

文件大小的票证:https://jira.atlassian.com/plugins/servlet/mobile#issue/JRA-9037/comment/49681