Hi @S_ANIL_KUMAR,
I was able to post attachments from Ignition.
My issue was for attachements that were over 64 Kb.
First, I changed the code of _socket.py (located in C:\Program Files\Inductive Automation\Ignition\user-lib\pylib on my server).
Changed the line 1207 :
sendall = send # FIXME see note above!
by :
def sendall(self, data, flags=0):
chunk_size = 8192
length = len(data)
data_view = memoryview(data)
idx = 0
while idx < length:
bytes_sent = self.send(data_view[idx:idx + chunk_size], flags=flags)
idx += bytes_sent
Then, I built the code below (I used some classes but you can simplify it as you need) :
from abc import ABCMeta, abstractmethod
# Abstract class -- do not instanciate
class JiraObject():
__metaclass__ = ABCMeta
baseUrl = "https://*.atlassian.net/rest/api/3/"
username = "username"
token = "apitoken"
proxyUrl = "proxyUrl"
@abstractmethod
def __init__(self):
self.id = None
def __getAuthToken__(self):
from requests.auth import HTTPBasicAuth
return HTTPBasicAuth(self.username, self.token)
def __getProxy__(self):
return {"https" :self.proxyUrl}
def get(self):
pass
def post(self):
pass
# Abstract class -- do not instanciate
class Issue(JiraObject):
@abstractmethod
def __init__(self, summary, description, project, issueType):
JiraObject.__init__(self)
self.summary = summary
self.description = description
self.project = project
self.issueType = issueType
def toString(self):
import json
issue = {"fields":
{ "summary" : self.summary,
"project" : {"key" : self.project},
"issuetype" : {"name" : self.issueType}
}
}
return json.dumps(issue)
def get(self):
pass
def post(self):
pass
class Bug(Issue):
def __init__(self, summary, description, project, issueType="Bug"):
Issue.__init__(self, summary, description, project, issueType)
def post(self, filePath=None):
import requests
import json
url = self.baseUrl + "issue"
headers = {"Accept": "application/json", "Content-Type": "application/json"}
with requests.request("POST", url, headers=headers, proxies=self.__getProxy__(), auth=self.__getAuthToken__(), verify=False, data=self.toString()) as response :
if response.ok:
self.id = json.loads(response.text)["id"]
if filePath != None :
attach = self.__addAttachment__(filePath)
if attach != None :
return self.id
else:
return "attach " + str(attach)
else :
return self.id
else:
return "pb >> " + response.text
def __addAttachment__(self, filePath):
import requests
url = self.baseUrl + "issue/" + str(self.id) + "/attachments"
headers = {'Accept': 'application/json', 'X-Atlassian-Token': 'no-check', "Accept-Encoding":"deflate"}
with open(filePath, "rb") as f:
files= {"file": ("capture.png", f, "application-type")}
with requests.request("POST", url, headers=headers, files=files, proxies=self.__getProxy__(), auth=self.__getAuthToken__(), verify=False) as response
if response.ok :
return str(response), str(response.text)
else :
return "ko" + response.text
Let me know if it helps 