Encoding Not supported Execption while parsing HL7 message - c#-4.0

I have a C#.NET application in which i am trying to construct an HL7 message and then send to other Application using NHAPI .The message is successfully constructed but it when i am trying to extract throws an error :Encoding NotsupportedException
Specifications:
.NET framework- 4
HL7 version-2.5
Language:C#
here is the piece of code
PipeParser ParserADT = new PipeParser();
IMessage ParsedADTmsg = ParserADT.Parse(ADTMsg);
string Msgstr = ParsedADTmsg.GetStructureName();
I get the exception immediately after the line above.
The constructed message:
MSH|^~\&|HIS|HIS1|||201405291223||ADT^A01^ADT_A01|73944|P|2.5
EVN||201405291223
PID|||102||Oberoi^Anjali^^^Ms||20140529|Female|||||^^PH|^^CP
NK1|1234||||||||||||||||||||||||||||||^^CP
PV1||Emergency –

Replace the space before EVN, NK1, and PV1 with a new line character, so that your message looks like this:
MSH|^~\&|HIS|HIS1|||201405291223||ADT^A01^ADT_A01|73944|P|2.5
EVN||201405291223 PID|||102||Oberoi^Anjali^^^Ms||20140529|Female|||||^^PH|^^CP
NK1|1234||||||||||||||||||||||||||||||^^CP
PV1||Emergency

Related

error trying to recreate php's dechex function in python3

i have a php file that takes a simple 8 digit id and converts it to hex using
dechex(intval($id))
i am now trying todo the same thing in python i start by grabbing my list of ids from the web these are returned as strings such as
00274956 , 00002645, 00000217
i then convert them to intagers and hex them using
hex(int(item_id))
but i am getting the error
ValueError: invalid literal for int() with base 10: 'init'
here is the code the id comes direct from a http get request
FILE_NUMBER = int(ITEM_ID)
FILE_HEX = hex(FILE_NUMBER)
FILE_NEW = FILE_HEX + ".pdf"

Apache Airflow did not recognize error in xml and report success

Hello Community I have a question for you, regarding a Python function. in Diser Function I read a large XML into a JSON format. In doing so I want to check if there is an tag within the XML at the first or last position, if so then raise error etc.
Unfortunately I have the problem that sometimes the function doesn't seem to recognize this tag and Apache Airflow then reports a success back.
For this I have then built a second function in advance, which checks the xml in advance via a Beautifulsoup.
But now I always get a failed reported.
Can you explain to me why the "old" checked a success reports, but soup cancels ?
Should I combine the two or is there a more elegant solution in general ?
def parse_large_xml(xml_file_name, json_file_name, extra_fields=None, clean_keys=True):
"""
Converts SAP xml response to json.
- processes the xml file iteratively (one tag at a time)
- capable to deal with large files
Args:
xml_file_name: input filename
json_file_name: output filename
extra_fields: extra fields to add to the json
clean_keys: flag, if set remove prefixes from the response keys
"""
######### Extra check #####
# This is the new extra check
with open(xml_file_name, 'r') as xMl_File:
data = xMl_File.read()
if "error" in set(tag.name for tag in BeautifulSoup(data, 'xml').find_all()):
logging.info(tag.name)
errorMsg= f"error in response file \"{xml_file_name} (XML contains error tag)"
logging.error(msg=errString, exc_info=True, stack_info=True);
raise RuntimeError(errString)
########################################################################################
# This is the old Check
if extra_fields is None:
extra_fields = {}
with open(json_file_name, 'w') as json_file:
for event, elem in progressbar.progressbar(ET.iterparse(xml_file_name, events=('start', 'end'))):
if 'content' in elem.tag and event == 'end':
elem_dict = xmltodict.parse(tostring(elem))
if clean_keys:
elem_dict = clean_response_keys(elem_dict)
response_dict = {'raw_json_response': json.dumps(elem_dict)}
response_dict = {**extra_fields, **response_dict}
response_dict['hash'] = hashlib.sha256(
response_dict['raw_json_response'].encode()).hexdigest()
response_dict['date'] = get_scheduled_date()
json.dump(response_dict, json_file)
json_file.write('\n')
elem.clear()
elif 'error' in elem.tag and event == 'end':
errString = f"error in response file \"{xml_file_name}\":\n{tostring(elem)}"
logging.error(msg=errString, exc_info=True, stack_info=True);
raise RuntimeError(errString)
I´m using Apache Airflow 1.10.15 and composer: 1.16.10 as well as Python 3.
Here is an example error xml as it is returned but not recognized
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code>
DBSQL_CONNECTION_NO_METADATA
</code>
<message>
Runtime Error: 'DBSQL_CONNECTION_NO_METADATA'. The OData request processing has been abnormal terminated. If "Runtime Error" is not initial, launch transaction ST22 for details and analysis. Otherwise, launch transaction SM21 for system log analysis.
</message>
<timestamp>
20220210031242
</timestamp>
</error>

Need to pass multiple variables to payload variables

I am trying to pass multiple variables to payload using format & +str(Var)+ but I am not getting the expected output. I have the hostnames in a file & get a password as input and want to pass it to the payload.
I am getting an error related to "Error while parsing JSON payload or an incompatible argument type for the requested resource"
for x in content:
url='https://url/a/b/c/{}'.format(x.strip())
payload=('{{"ip-address": "x.x.x.x","user-name": "john","password": "'+ str(Pass) +'","db-name": "'+ str(x.strip()) +'","service-name": "y","port": "y","connection-string": "y"}}')
response = req.post(url,json=payload,headers=add_cookie,verify=False)
======================
for x in content:
url='https://url/a/b/c/{}'.format(x.strip())
payload={"ip-address": "x.x.x.x","user-name": "john","password": "{}","db-name": "{}","service-name": "y","port": "y","connection-string": "y"}.format(Pass, x.strip())
response = req.post(url,json=payload,headers=add_cookie,verify=False)
In first part your payload is a string and not a dict, it should be
payload={"ip-address": "x.x.x.x","user-name": "john","password": str(Pass),"db-name": str(x.strip()),"service-name": "y","port": "y","connection-string": "y"}
In the second one you're using the format function on a dict type which is wrong.

Recursively getting body of email with Pyzmail module

I'm trying to create an app that needs to recursively check an email address for new emails and then do some other stuff; I'm having some problems with the getting the body of the emails, though. I'm using the pyzmail module alongside imapclient, and the Automate the Boring Stuff for guidance (with python 3.6). Here's my code:
mail = imapclient.IMAPClient('imap.gmail.com', ssl=True)
mail.login('email', 'password')
mail.select_folder('INBOX', readonly=False)
uid = mail.gmail_search('NC')
for i in uid:
message = mail.fetch(i, ['BODY[]'], 'FLAGS')
msg = pyzmail.PyzMessage.factory(message[i][b'BODY[]'])
msg.html_part.get_payload().decode(msg.text_part.charset)
But it's not working. I've basically tried different forms of this code but to no avail and there's really not that many examples that can help me along. I'm a bit of a python newbie. Can anybody help?
Thanks,
EDIT
I realized where I made a mistake and fixed a bit of the code:
server = imapclient.IMAPClient('imap.gmail.com', ssl=True)
server.login('p.imagery.serv#gmail.com', 'rabbitrun88ve')
server.select_folder('INBOX', readonly=True)
uids = server.gmail_search('NC')
for i in uids:
messages = server.fetch(i, ['BODY[]'])
msg = pyzmail.PyzMessage.factory(messages[b'BODY[]'])
The problem I'm having is with the last line, which I dont know how to fed using the variables that is created with the iterator. It throws out this message:
ValueError: input must be a string a bytes, a file or a Message
I'm not sure if you still have this problem but for those who might have similar issues in future.
I noticed a little omission in the last line which might be the culprit.
msg = pyzmail.PyzMessage.factory(messages[b'BODY[]'])
You omitted the 'i' variable of the for loop
msg = pyzmail.PyzMessage.factory(messages[i][b'BODY[]'])
I'd like to do next to get body text of searched messages:
server = imapclient.IMAPClient('imap.gmail.com', ssl=True)
server.login('p.imagery.serv#gmail.com', 'rabbitrun88ve')
server.select_folder('INBOX', readonly=True)
uids = server.gmail_search('NC')
rawmessage = server.fetch(uids, ['BODY[]'])
for i in rawmessage:
msg = pyzmail.PyzMessage.factory(rawmessage[i][b'BODY[]'])
msg.html_part.get_payload().decode(msg.text_part.charset)
In this case, you get iteration over fetched emails with body text. I checked similar example but I used text_part.get_payload() instead html regarding features of my server.

Netsuite CSV import(An unexpected error has occurred)

Below is the sample code, i am using in CSV Import process.
var createJob = nlapiCreateCSVImport();
createJob.setMapping("CUSTIMPORTcust_pay");
createJob.setPrimaryFile("Data_string");
createJob.setOption("jobName", "Test imports");
var JobId = nlapiSubmitCSVImport(createJob);
nlapiSubmitCSVImport function is returning JobId without any error, but in job status page[UI] it showing status is failed and in Message field it showing "An unexpected error has occurred", CSV Response field also empty. when i try this by running the above code with same data again, some time it is successfully imported and some time it got failed, with showing message "An unexpected error has occurred"
Please see setPrimaryFile(file).
Where file is either:
The internal ID, as shown in the file cabinet, of the CSV file containing data to be imported, referenced by nlapiLoadFile. For example:
.setPrimaryFile(nlapiLoadFile(73))
Raw string of the data to be imported.
You are passing in a raw string of "Data_string".

Resources